Quantcast
Channel: MATLAB Central Newsreader - tag:"simulink"
Viewing all 316 articles
Browse latest View live

Simulink unexpected asymptotic behavior

$
0
0
Hello! I am having trouble with my simulink model. I have coupled second order differential equations, one of which has a forcing function on it. The equations of motion are as follows (using xdd to express "double dot" or the second derivative, and xd for "dot" or the first derivative):

m1xdd1+c(xd1-xd2)+k1(x1-x2)=0
m2xdd2+c(xd2-xd1)+k1(x2-x1)+k2x2=0.01*k2*sin(wt)
where m1, m2, k1, k2, c, and w are all constants. This is a function of x1, x2, and time.

Everything is wired up correctly, and the expected result would be some sort of combined sinusoidal curve. However, I have been getting a flat line up until the end of my time interval, where it shoots to infinity. It shoots to infinity if I end the interval at 2 seconds, 5 seconds, 10 seconds, whatever--it is always at the end. For a larger time interval (20s), an error occurred stating that at one integrator, there was an infinite value. This integrator was connected to the forcing function so I believe it is a problem with my initial conditions.

I saw on another forum with someone with a problem with drift, where someone stated that there was a problem with initial conditions and that it should be a function of w. I tried figuring out that initial condition by integrating that function (0.01k2sin(wt)), getting -k2/w*0.01*cos(w*t), plugging in t=0, but the problem is still occurring.

I've tried messing with my tolerances as well (this was what the error message suggested), but I don't believe that is the issue because of the flatline result for a majority of the graph.

Any help would be appreciated!

Re: Error to Use SimCoupler

$
0
0
"Andi Muhammad Nur Putra" wrote in message <nnneaj$4oj$1@newscl01ah.mathworks.com>...
> I got this error message when trying to use simcoupler to perform co-simulation between Matlab and PSIM.
>
> Cannot find an exact (case-sensitive) match for 'PsimDialog'
> The closest match is: PSimDialog in C:\Program Files\MATLAB\R2014a\toolbox\simulink\SimCoupler\PSimDialog.m
> Error using struct2handle
> Error while evaluating uicontrol CreateFcn
>
> Please help me to solve this problem.
> thanks for your help

With the option "Set Path" in MATLAB, I included the folder where PSIM is Installed

Re: Stream data form MATLAB to Simulink

$
0
0
"Michal" wrote in message <ka5id3$hle$1@newscl01ah.mathworks.com>...
> You still don't get a point... :/ Ok, then, I'll try to show you something:
>
> 1. Build a model in Simulink, just as you wanted me to build, and in addition connect a Scope to the output of Constant. Put an 'a' inside a Constant as parameter, and set inf for a time simulation.
>
> 2. Create a m-file with a simple code just like this one:
>
> tic
> for i= 1:1000
> a=int2str(i)
> set_param('model1/Constant','Value',a);
> end
> toc
>
> 3. Set an a for a initial value a=0;
> 4. Start A Simulink model.
> 5. Start a m-file script
> 6. Wait for a script to reach it's end (takes approximately 1.4 sec. on dual core 2 ;) )
> 7. Stop a Simulink model
> 8. Open a Scope...
>
> And then you will finally know that the problem is... You see know? If still don't I'll explain one more time: For the beginning the model1 was running with a=0 and displaying that value... Then when you've started a m-file script it pauses... waits until it ends and continue to run with the LAST value of parameter a, which is in that case 1000. I can record a movie if it's still not enough clear what the problem is. ;)




Hello michal...do find a solution for problem?? i also have problem with this..try to get output from m code into my simulink block??

Why is simulink constant block labelled as “Fixed in Minor Step”

$
0
0
I have a Constant block with Sample time = inf in an otherwise empty model, and when I click Display/Sample Time/Colors, it shows the sample time for this block as gray, indicating "Fixed in Minor Step". This is a bit surprising, since there is an extra category for "Constant". Is this expected behavior, and if not, what could I have messed up in my settings?

I first noticed this in a more complex model, where a subsystem with a combination of discrete and constant inputs was labelled "Fixed in Minor Step". According to the 2nd-last line of this page of mathworks documentation, combinations of constant blocks with discrete ones should not be designated as having hybrid sample times.
https://mathworks.com/help/simulink/ug/managing-sample-times-in-systems.html

I am seeing this behavior in both 2014b and 2015a releases on linux.

Note: originally posted here: http://stackoverflow.com/questions/40789734/why-is-simulink-constant-block-labelled-as-fixed-in-minor-step

Re: Simulink Problem

$
0
0
"Amit" wrote in message <ik8gsk$15$1@fred.mathworks.com>...
> I need to use the neutral network predictive controller. I have already built the plant system, but when I try to define the simulink plant model in the plant identification part, the system always warned me “ you must enter a valid filename for your Simulink plant model” , I tried to put my model file into the default path, change some similar name like the example, but none of them work.If anyone has any suggestions I will be really appreciated.
Hello,I meet the same with with you.So if you solved this problem,could you give me some advise?I will be very appreciate.

Re: Why is simulink constant block labelled as “Fixed in Minor Step”

$
0
0
two additional pieces of information:
the part of the more complex model which is marked as "Fixed in Minor Step" is a feedback loop. There is a delay block in the loop, otherwise it would be an algebraic loop. If I disconnect the loop at any point, then everything is labelled discrete - as it should be. Since most of the sample times except the constant blocks are defined as inherited (-1) and the inheritance can still propagate around the loop, I am not sure why the (missing) connection makes a difference.

The model runs, and the results appear to be correct, however I assume that the execution time would be considerably faster if the model was evaluated at discrete time points rather than on the time scale of the solver.

Re: how to keep WS2_32.lib as a static library rather than converting into WS2_32.dll?

$
0
0
"Yongxiang Fan" wrote in message <mmtd6v$t7d$1@newscl01ah.mathworks.com>...
> Dear all,
> I am working on simulink real time in Target PC. Due to linking reason, I have to add WS2_32.lib into VS2010 Compiling environment. However, the target PC doesn't accept dll file.
>
> Do anybody knows how to fix this? Thank you in advance!!
>
> Best,
> Yongxiang Fan


Hello!

I have the same problem. Did you fix it?

Best regards!

Re: legacy code tool with complex c functions

$
0
0
Well, I can see this question rather old, but still I would be very interested in a answer as well.
Especially if this answer qould solve the problem of returning multiple return values from a single function.

Currently I am looking into a solution, that somewhat interacts similar to a mexFunction.
e.g. [int y1, int y2] = fun(int u1, int u2)

I stumbled upon an example that mentioned following struture:

Declared in mex.h (line 141+ in R2014b)

void mexFunction (
        int nlhs, /* number of expected outputs */
        mxArray *plhs[], /* array of pointers to output arguments */
        int nrhs, /* number of inputs */
        mxArray *prhs[], /* array of pointers to input arguments */
);


If this could be implemented with the support of the legacy_code tool, it would be fantastic, but I fear I mistunderstood something. The problem should be 'mxArray' since it isn't a supported Datatype as far as I can see.

Still, I would be happy if someone had a solution that would help me to receive multiple values from one called function / method by a wrapper function utilized with the legacy_code tool.


With best regards,
Christian


"Laura" wrote in message <hovvr0$m1t$1@fred.mathworks.com>...
> Hello,
>
> I have a fairly complex c function that I need to call in simulink using the legacy code tool. Specifically, this function returns multiple outputs by expedient of passing in a structure variable by reference. Within the function, the values in this structure are updated. When I use this function within a c library, the calling program then grabs the updated values to finish whatever processing is required.
>
> Now, I'd like to be able to call this function from a simulink model. However, according to the documentation at "http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/sfg/bq4g1es-1.html#bq4g1es-6" on how to do so, I cannot actually do this because the function must not change the value of of input arguments, and that is what I end up doing. Nor can I modify my function to return a reference to the output structure, since the same rules state I can't have a function return a pointer.
>
> Now, I don't see anything that indicates I can't simply return the output structure directly, but I can't seem to find any directions on how this is actually done. Can someone point me to an example? For that matter, are there any examples of using the legacy code tool with pointers to structures as inputs to a function?
>
> Thanks,
> Laura

Re: Loading wrl file to GUI

$
0
0

hello.
i want to simulation wrl.file in matlab gui.
so i finded your posting and i tried it.
How do i simulatate GUI........first i runned simulink and then started gui.
but i only succeeded load wrl file in gui but it didn't moved..
In my gui, wrl file is being stopped like image.....
i thought your comment that if simulink is runned, in gui, the wrl file is animated automatically!
I wait your good reply!
 thanks!

my Code
---------------------------------------------------------------
function b1_Callback(hObject, eventdata, handles)
% hObject handle to b1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Set the viewer preference
vrsetpref('DefaultViewer', 'internalv5')

%Obtain vrworld and construct canvas
w = vrworld('vrml1');
open(w);

%Create the MATLAB GUI with two views of the robot
c1 = vr.canvas(w, gcf, [20 10 250 400]);
set(c1,'Units','normalized')

start(handles.timer)
function GUIUpdate(hObject, eventdata, handles)

global t U

t = evalin('base','time');
U = evalin('base','output');
set(handles.plot,'xdata',t,'ydata',U);

--------------------------------------------------------------------------------------------------------

"Simulink Dude" wrote in message <hnj8ic$cb5$1@fred.mathworks.com>...
> Hi there,
>
> Since R2009a, we have functionality in Simulink 3D Animation that lets you add VRML 3D worlds inside MATLAB GUIs and animate them.
>
> Here is an example code that accomplishes the same for a VRML file: industrial_robot.wrl
>
> % Set the viewer preference
> vrsetpref('DefaultViewer', 'internalv5')
>
> %% Obtain vrworld and construct canvas
> w = vrworld('industrial_robot');
> open(w);
>
> %Create the MATLAB GUI with two views of the robot
> c1 = vr.canvas(w, gcf, [20 10 250 400]);
> set(c1,'Units','normalized')
> % c1.Viewpoint='Left_View';
>
> Please note the animation is automatic if you used Simulink with the VR Sink block and added this code on top of that. But if you use MATLAB, then you would have to access the appropriate VRML nodes in order to animate them. There is a video/demo that shows how to do that for a wind farm:
>
> http://www.mathworks.com/matlabcentral/fileexchange/26273-animate-a-wind-farm-with-matlab
>
> Thanks,
>
> Saurabh

Passing many parameters to Matlab Function Block in Simulink

$
0
0
Hi,

I'm using a matlab function block and I'm trying to load several arrays from a .mat file into the matlab function.

In the function block, using the load datafiles.mat doesn't work and gives me "The output of a call to 'load' is not assigned to a variable. Assign its output to a variable without subscripting."

I've also tried saving the data from the matfile into a struct and trying to pass the struct to the matlab function block but had similar problems.

The mat file has close to 40 aircraft parameters and I want to avoid having to manually make 40 constants in simulink to pass as inputs to the matlab function bock.

Any suggestions on how to get these parameters into the matlab function block?

Best,

Qam modulator and demodulator without using blocks

$
0
0
Does anyone have any idea how can I implement a 16-qam modulator and demodulator without using the simulink modulator blocks ?

Re: Simulink S-domain Transfer function to Z-domain Transfer function

$
0
0
"Phil Goddard" wrote in message <h368k9$k38$1@fred.mathworks.com>...
> Assuming your transfer funtion is LTI (linear, time invariant) then there are functions within the Control Toolbox that will do the transformation for you.
>
> If you don't have Controls Tbx then do a search for Tustin or Bilinear Transform and write some MATLAB code that does the conversion prior to running the simulation, and have a discrete transfer function block in your model use the results.
> The transformation isn't difficult to implement.
>
> Phil.

Respected sir,
 
Will you give live/simulink/editor example of the above question taking z-domain

Re: Simulink Problem

$
0
0
"Amit" wrote in message <ik8gsk$15$1@fred.mathworks.com>...
> I need to use the neutral network predictive controller. I have already built the plant system, but when I try to define the simulink plant model in the plant identification part, the system always warned me “ you must enter a valid filename for your Simulink plant model” , I tried to put my model file into the default path, change some similar name like the example, but none of them work.If anyone has any suggestions I will be really appreciated.

my solution:
create your model, save in nncontrol folder. change your plant name as robotarm.

sfrotaion

$
0
0
I am new to Simulink 3D Animation. I have been trying to use the Simulink 3D World Editor. My aim is to translate and rotate a helicopter model. I was able to create the 3D world along with the helicopter. My model is accurate when it comes to translation, but I am not able to understand how rotation works. I have checked the sfrotation block in block parameters. But when I input 3by1 matrix to rotation input of vrsink block in Simulink, it says dimensions are not correlating and asks for 4th dimension. Can someone please explain how can I get accurate rotation of my model in all 3 axis(roll, pitch, yaw)?

Re: How to connect model from simpowersystems to model from simscape

$
0
0
On Wednesday, January 20, 2010 at 10:23:04 PM UTC+5:30, Arnaud Miege wrote:
> "Dangdang Shao" <bolanggu@yahoo.com.cn> wrote in message <hhq82n$rm6$1@fred.mathworks.com>...
> > Hi,
> >
> > I want to set an electrical model by simulink. I need to use current controlled current source, which is only available in simscape. However, the rest of the model is set by simpowersystems. I find I can't connect the blocks of these two libraries.
> >
> > I once found Arnaud Miege's comments here, that is,
> > "You can create an interface between SimPowerSystems and Simscape by measuring current in SimPowerSystems and injecting it in Simscape, and measuring voltage in Simscape and injecting it in SimPowerSystems."
> >
> > I tried in this way but I still failed to connect the models:(
> >
> > Can anybody give me some idea or help?
>
> In SimPowerSystems, measure the voltage (in parallel) with a voltage measurement block, which outputs a Simulink signal. Feed this signal into a S-PS block to convert it to a physical signal and inject this to a controlled voltaged source in Simscape.
>
> On the Simscape side, measure the current (in series) with a current sensor block, which outputs a physical signal. Feed this signal to a PS-S block to convert it to a Simulink signal, and inject this to a controlled current source in SimPowerSystems.
>
> Note that this introduces an algebraic loop in the model, which may cause numerical problems. Note also that you can't have two current sources in series, so you may need to insert a small resistor to make it work, depending on how the rest of your model is structured.
>
> HTH,
>
> Arnaud

Hi Arnaud,


I want to connect a rechargeable generic battery, which is actually in simulink to a dc motor (which is in simscape). I tried to connect it
(from battery side) voltage measurement->s-ps->controlled voltage source->dc motor, but in that case controlled voltage source is working as a voltage source for the motor means it is not loading the battery(battery is not getting discharged). Please give some idea how can I do this...

Understanding links between library blocks

$
0
0
Hi,

I'd like to create my own subsystem with block from Simulink Library (Transfer Fcn for example).
Let's assume I do it with MATLAB 2012, and then I re-use my subsystem in MATLAB 2016 and in meantime, Tranfert FcN has evolved in Simulink.

How will behave my "Transfer Fcn" block in my subsytem:
- As in MATLAB 2012 ?
- As in MATLAB 2016 ?

The goal is to know if I would have to validate again my subsytem under 2016, if I already did it in 2012.

Thanks.

Re: Automatic layout of Simulink model?

$
0
0
Rex Eastbourne <rex.eastbourne@gmail.com> wrote in message <1180312707.073784.84510@w5g2000hsg.googlegroups.com>...
> On May 24, 4:49 am, Michael Salloker <michael.No.sallo...@fh-
> joanneum.SPAM.at> wrote:
> > Rex Eastbourne schrieb:
> >
> > > Hi,
> >
> > > I'm working on a Simulink model with about 25 blocks, and things are
> > > starting to look messy. Is there any way to automatically lay out the
> > > block diagram so that it's easier to digest visually?
> > > In other words, I'm looking for automatic placing and routing of
> > > edges. Is there a way to do this?
> >
> > > Thanks,
> > > Rex
> >
> > Hello Rex,
> >
> > I think the grid feature in SImulink it is not very well known. The
> > reason seems to be, that its existence is not obvious. You can activate
> > and modify it only using the set_param command.
> >
> > The option showgrid toggles the display of a grid, and the option
> > gridspacing allows to set the spacing in multiples of 5.
> >
> > Then you can move and aline your blocks with the mouse and/or the cursors.
> >
> > However, it is not so convnient like similar tools in graphic programs.
> > First it must be easier to use this option and second, the model does
> > not store the actual settings of this two options. I think this is a
> > point, where an improvement should be done.
> >
> > Michael
> >
> > PS: There exists also a hard variant for block positioning, using the
> > position option of a block.
>
> Thanks!!!
>

I know my response is very late, but I will post this in case someone stumbles upon this question as I did. This tool may do what you are looking for: https://www.mathworks.com/matlabcentral/fileexchange/51228-auto-layout-tool

How to create a block that acts like a switch to input new values to a simulation

$
0
0
I have a Simulink code. My code is simulating four motors running when my PID controller sends RPM signals. I want to create a 'switch' block such that when I click it (time invariant) during the simulation, the RPM signals becomes zero.

Which blocks do I use to do this? The Switch commands takes inputs. I do not want my blocks to have inputs. Just outputs. When I click it, the block should re-write new values.

MATLAB Interpreted Function

$
0
0
In a Simulink, I used MATLAB interpreter function to numerically solve a gigantic algebraic equation with 12 parameters (which these parameters result from the other block in that model). Whenever I run this function in Command window and import these variables manually it works properly. However, if I use this function in MATLAB interpreted function, I get the error saying that: "Error in 'untitled/Interpreted MATLAB Function'. Evaluation of expression resulted in an invalid output. Only finite double vector or matrix outputs are supported". I really appreciate it if you can help me to fix this. Really need help ASAP, Thank you so much!

edit model in matlab

$
0
0
I want to add or edit library in a model implemented in matlab toolbox but this message appear
 
:Attempt to modify link 'power_SVPWMGenerator2Level/SVPWM Generator (2-Level) 2/Model'. You can disable this link now and restore later."

I can't move any block. If disabled the link the file corrupted.
Viewing all 316 articles
Browse latest View live