COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Simulink Vs Matlab Diff. Equations.

• Email
• Follow

```Guys, this is my first post!

My question is why do i get slightly different results when computing differential equations using matlab or simulink.

Here is my equation.

2nd derivative v * 1st derivative v * v

I am using 4th order Runge Kutta in both with fixed time step of 0.5. Qualitatively they are almost identical but not quite. Surely they should be the same. Am I doing something wrong.

function [dxy] = diffxy(t, xy)
x1 = xy(1);
xdot1 = xy(2);
xdot1 = xdot1;
xdoubledot1 = - xdot1 - x1;
dxy = [xdot1; xdoubledot1];
```
 0

See related articles to this posting

```Guys ignore this, have tried with other solvers, A OK. Must have slightly diff. implementations of RK 4.

"thomas " <thomashenryalderson@hotmail.com> wrote in message <icrn9k\$osb\$1@fred.mathworks.com>...
> Guys, this is my first post!
>
> My question is why do i get slightly different results when computing differential equations using matlab or simulink.
>
> Here is my equation.
>
> 2nd derivative v * 1st derivative v * v
>
> I am using 4th order Runge Kutta in both with fixed time step of 0.5. Qualitatively they are almost identical but not quite. Surely they should be the same. Am I doing something wrong.
>
> function [dxy] = diffxy(t, xy)
> x1 = xy(1);
> xdot1 = xy(2);
> xdot1 = xdot1;
> xdoubledot1 = - xdot1 - x1;
> dxy = [xdot1; xdoubledot1];
```
 0

```Nope, right the first time, why is this? Only slightly differing results.

"thomas " <thomashenryalderson@hotmail.com> wrote in message <icrn9k\$osb\$1@fred.mathworks.com>...
> Guys, this is my first post!
>
> My question is why do i get slightly different results when computing differential equations using matlab or simulink.
>
> Here is my equation.
>
> 2nd derivative v * 1st derivative v * v
>
> I am using 4th order Runge Kutta in both with fixed time step of 0.5. Qualitatively they are almost identical but not quite. Surely they should be the same. Am I doing something wrong.
>
> function [dxy] = diffxy(t, xy)
> x1 = xy(1);
> xdot1 = xy(2);
> xdot1 = xdot1;
> xdoubledot1 = - xdot1 - x1;
> dxy = [xdot1; xdoubledot1];
```
 0

2 Replies
543 Views

Similar Articles

12/11/2013 4:57:27 PM
[PageSpeed]

Similar Artilces:

Need to use Matlab to create a tool to solve & plot cpled diff. equations
Need help from a tutor or somebody who can just do this. Don't think it's very hard for an experienced matlabber. Willing to pay. I need a tool to solve and plot the results of a few simple coupled differential equations. The end product needs to be something that a non-technical person can use to plug in some values for variables, and have the program report on the other variables and plot the results in a few simple graphics. Can you help? Please reply if you can or know somebody. ...

floating point programming: c/c++ vs matlab vs fortran vs ???
Dear all, I am helping someone code a model of an optical amplifier in C code (with the aim of verifying results published by someone else). The model seems to behave correctly for a limited range of parameters, but is quite off outside this range. This is unacceptable; AFAICT theres no algorithmic reason the model should fail, so I suspect things are going wrong in floating point land. As I've been reading up on the matter I find there is a lot that could be going wrong: floating point exceptions, rounding errors etc. The model can be run reasonably quick, so we'd happily sacrifice ...

solving an equation in matlab
Hi, I wanted to know if there were any inbuilt commands in matlab to solve the equation of the form f(x)=0 numerically. The function f(x) is composed of user written functions. I would really appreciate any help of this as I need it for some urgent work. Thanks. In article <ef26062.-1@webx.raydaftYaTP>, "Apoorva Shende" <apoorvashende@indiatimes.com> wrote: > Hi, I wanted to know if there were any inbuilt commands in matlab to > solve the equation of the form f(x)=0 numerically. The function f(x) > is composed of user written functions. I would really apprecia...

hi all i would like to do this command in simulink thanks sum(abc(:,2)) ...

equation diff #3
when I carry out ode_ex.m I have the following error which is posted: Warning: Failure at t=5.179723e-001. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (1.840207e-015) at time t. (Type "warning off MATLAB:ode45:IntegrationTolNotMet" to suppress this warning.) > In C:\MATLAB6p5\toolbox\matlab\funfun\ode45.m at line 335 In C:\MATLAB6p5\work\backstep\ode_ex.m at line 4 %%%%%%%%%%%%%%%ode_ex.m%%%%%%%%%%%%%%%%%%%% t0 = 0.0; tf = 1; tspan = [t0 tf]; X0 = [0.0; 0.0; 0.0; 0.0 ;0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0 ;0.0; 0.0; 0....

MatLab FFT vs. Fortran
Hi NG, Don't know if this is the correct place to post this, but I hope there are some people out there with experience in both MatLab and Fortran. I have a signal, which I Fourier transform with fft() in MatLab. The result of this operations is of course the frequency components expressed in an array of complex numbers. I then use a Fortran routine (rfour) to transform the _same_ signal, but I then get an array of significantly different complex values - both in value and sign?! I realize of course it is hard for anybody to guess why this happens since they don't have or know the F...

Matlab vs. C runtime
Why is matlab considered to be slower than C++ ? Is this an historical myth that is not valid anymore ? Is it dependent on the task you are programing ? For example, are logical IF take the same time in C++ and Matlab ? Are vector operation or memory re-allocations faster in either one ? I would be happy for some reference on the subject. Eldad. ...

.... in matlab 5.0 and accompanying simulink version, how does one use a toolbox leftover from ver4.2 or some specific toolbox from internet-is adding it to path enough to appear in simulink? ...

Resampling in Photoshop VS Matlab
Hello, I'm trying to duplicate the resize fucntions in Photoshop (NN, Bilinear, Bicubic), in Matlab. However, the imresize function using the same resizing method does not result in duplicate images. I have tried downsampling in Photoshop, then with imresize using the same size and function. However after a pixel by pixel comparison, the images are not duplicate. Does anyone know how to "simulate" the photoshop resizing functions in MAtlab to produce an identical image as Photoshop would? Perhaps it has to do with anti-aliasing, rounding, quantization? ...

Hi, I have a problem with the Embedded MATLAB Function in SIMULINK. So if any one could help me once again ! Thank you very much in advance for the answer. I have build the model using the following block in Simulink : 1- Block Embedded MATLAB Function : function signal = readsound fe = 44100; signal = zeros(1, fe); [FileName, PathName] = uigetfile('*.wav', 'Ouvrir un fichier SON'); [signal, fe] = wavread([PathName FileName ]); 2- Block : To Wave Device I do not understand these errors: - Source : To wave device Error reported by S-function 'sdspwao2' in 'wave...

While working on a project for a class, I encountered the following error involving a certain MATLAB function: "Error in port widths or dimensions. Output port 1 of block 'slrcrndy2/slrcrndy.m' is a one dimensional vector with 7 elements" along with "Error in port widths or dimensions. Input port 1 of block 'slrcrndy2/Demux' is a one dimensional vector with 11 elements" Now, it seems obvious what this means. However, when I change the output dimensions in the block parameters window from -1 to 11, I get this error: "Error evaluating MATLAB ...

hello all, I have a model in Simulink which uses several Embedded MATLAB blocks. The input comes from the MATLAB workspace as a vector with around 10^5 bits. The model compiles succesfully and generates a mex-file;however, when it tries to run it it gives an error: Invalid MEX-file: Not enough storage is available to process this command. I've tried using a smaller input containing around 200 000 bits and it works but with another input with 400 000 bits it generates the error. I'm sure it is not a computer problem as I've tested it on different computers running MATLAB R2008a a...

Matlab Fmincon vs Cplex?
Hello, I am trying to develop a java program that will integrate Cplex to rewrite a Matlab code. Matlab is so slow and I was thinking that with Java and Cplex I could take care of that. However I got stuck at some point. In matlab code there is a statement like: h = fmincon(@SIPlowerlevel_outer,h0, [], [], Ytrain', 0, zeros(length(Ytrain),1), best_C*(ones(length(Ytrain),1)), [], options); save h g2 = fmincon(@upperlevelSIP,[0 0 1 ],[],[],[],[],-100,100,@nonlincon_outer,options); With matlab Fmincon (with active set method) is used, however I could not find what I sho...

Model rate equation by matlab
Hi, I tried to solve the model equation given by P. Beker in chapter 6(page 157) of book"erbium doped fiber amplifier". i put all the required parameters he had given. but while plotting gain vs length the graph is opposite. i don't know what is the problem. the code i had written in matlab is here %functiongains.m function ygprime = functiongains(lg,yg); global h t R A os op1 op2 N delv sas5 ses5 sas3 ses3 sap9 sep9 sap4 sep4 global c ls lp vs vp ns np ds dp N2 alphas alphap yg5=yg(3)+yg(4); N2=N*(ns*os*yg(2)+ns*os*yg5+ np*op2*yg(1))/(ds*os*yg(2)+ds*os*yg5+dp*op2*yg(1)+1); N2/N...

How to use MatLab ode45 for equations of motion?
Hi, I would like to make a model in MatLab that calculates the 2-D motion of a rigid-body projectile. The model will include the atmospheric properties as a function of altitude, gravity and the drag force acting on the projectile. For the drag force I will be using tabulated drag coefficient data that is a function of Mach number. The duration of the trajectory is not known in advance and the trajectory will end when the projectile reaches the ground (zero altitude). I've taken a look at the MatLab help guide and seen there's a 4th-order Runge-Kutta method but I cannot see how t...

RAM vs. CPU bottleneck for MATLAB?
Assuming that I have optimized my code for memory usage, and I have a fairly well balanced hardware loadout, would increasing my RAM alone be likely to increase the speed of MATLAB program runtimes? or is CPU more of the bottleneck almost no matter what? Dear Gavin! > Assuming that I have optimized my code for memory usage, and I have a fairly well balanced hardware loadout, would increasing my RAM alone be likely to increase the speed of MATLAB program runtimes? or is CPU more of the bottleneck almost no matter what? It depends. What do "optimized for memory usage" mean? The...