From: Marco Letizia on 28 Apr 2010 10:28 "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <hr9fre$feo$1(a)fred.mathworks.com>... > "Marco Letizia" <letissier85(a)hotmail.com> wrote in message <hr9etc$cke$1(a)fred.mathworks.com>... > > > the problem is: > > > > i used the command "load variabili" because the script in which i need to solve the differential equation accept as input those variables, and i need them into the .m file of the function. > > NO. You don't need to load it. READ MY response. > > When you create the function handle, those variables > are available to the function to use. They are passed > in properly. You will find the difference is significant, > by avoiding those wasted loads. > > > > Obviously the function i posted is in a .m file and i run this function calling it into the terminal with : > > > > tstan=[0 t_srotolamento]; > > > > y0=[0 0]; > > > > [t,y]=ode45('eq_diff',tstan,y0); > > > > t > > > > y > > > > I have to say that the problem occourred when i added the massatot*g*d*cos(y1) part. Without that part, i had correct plots and outputs from the function, that's why i was wondering if i did some mistake writing the last part of the function. > > If you are have a term in it that reads like this... > > massatot*g*d*cos(y1) > > then I would expect an error. Matlab does not > know what y1 is. If this was a typo on your part > in this post, then show us what the error was. > > John sorry, the correct (or, this is what i think) part is: massatot*g*d*cos(y(1))
From: Marco Letizia on 30 Apr 2010 05:21 "Marco Letizia" <letissier85(a)hotmail.com> wrote in message <hr9gll$ef1$1(a)fred.mathworks.com>... > "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <hr9fre$feo$1(a)fred.mathworks.com>... > > "Marco Letizia" <letissier85(a)hotmail.com> wrote in message <hr9etc$cke$1(a)fred.mathworks.com>... > > > > > the problem is: > > > > > > i used the command "load variabili" because the script in which i need to solve the differential equation accept as input those variables, and i need them into the .m file of the function. > > > > NO. You don't need to load it. READ MY response. > > > > When you create the function handle, those variables > > are available to the function to use. They are passed > > in properly. You will find the difference is significant, > > by avoiding those wasted loads. > > > > > > > Obviously the function i posted is in a .m file and i run this function calling it into the terminal with : > > > > > > tstan=[0 t_srotolamento]; > > > > > > y0=[0 0]; > > > > > > [t,y]=ode45('eq_diff',tstan,y0); > > > > > > t > > > > > > y > > > > > > I have to say that the problem occourred when i added the massatot*g*d*cos(y1) part. Without that part, i had correct plots and outputs from the function, that's why i was wondering if i did some mistake writing the last part of the function. > > > > If you are have a term in it that reads like this... > > > > massatot*g*d*cos(y1) > > > > then I would expect an error. Matlab does not > > know what y1 is. If this was a typo on your part > > in this post, then show us what the error was. > > > > John > > sorry, the correct (or, this is what i think) part is: > > massatot*g*d*cos(y(1)) i didn't receive any new positive comment... let's modify the question: how would you write and solve in matlab the following differential equation? m*g*r-kv*r*θ'-kr*r+M*g*d*cosθ=( I+m*r^2)θ''
From: Steven Lord on 30 Apr 2010 09:47 "Marco Letizia" <letissier85(a)hotmail.com> wrote in message news:hre7e1$fba$1(a)fred.mathworks.com... > "Marco Letizia" <letissier85(a)hotmail.com> wrote in message > <hr9gll$ef1$1(a)fred.mathworks.com>... *snip* > let's modify the question: how would you write and solve in matlab the > following differential equation? > > m*g*r-kv*r*θ'-kr*r+M*g*d*cosθ=( I+m*r^2)θ'' Well, I don't know which character θ is offhand, but looking at the general structure I'd convert this second order ODE into a system of first order ODEs as described in the "van der Pol Equation (Nonstiff)" example: http://www.mathworks.com/access/helpdesk/help/techdoc/math/f1-662913.html#brfharp-1 incorporating the nested function approach described in "van der Pol Equation (Parameterizing the ODE)": http://www.mathworks.com/access/helpdesk/help/techdoc/math/f1-662913.html#brfharp-9 or the anonymous function approach described here: http://www.mathworks.com/support/solutions/en/data/1-1AIJF/?solution=1-1AIJF to get all the additional parameters into the ODE function. Then just call one of the ODE solvers -- start with ODE45 and if that's too slow (due to your problem being stiff) switch to a stiffer solver. The documentation pages I linked to above contain a table at the beginning describing which solvers are suitable for stiff problems and which are not. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
First
|
Prev
|
Pages: 1 2 Prev: Recognizing a key hit while running Next: file 'ntwin32.mak' not found |