what wrong in my code when i use ode 45,and what the error are mean
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
avrham malasa
le 21 Jan 2020
Commenté : avrham malasa
le 22 Jan 2020
function [dw,ds] = Mass_On_Stick_012345678(w,s,parameter)
%Parameter=[ b m R G g ]
b=parameter(1);m=parameter(2);R=parameter(3);G=parameter(4);g=parameter(5);
fi_1=w(1);
fi1_dot=w(2);
teta_1=s(1);
teta1_dot=s(2);
%%rt=R*[sin(teta_1)*cos(fi_1),sin(teta_1)*sin(fi_1),cos(teta_1)];
dw=[0;0];
dw(1)=fi1_dot;
dw(2)=(-fi1_dot)*((2*teta1_dot)/tan(teta_1)+(b/m));
ds=[0;0];
ds(1)=teta1_dot;
ds(2)=(g/R)*sin(teta_1)-((G*teta_1)/(m*(R^2)))+0.5*(fi1_dot^2)*sin(2*teta_1)-((b*teta1_dot)/m);
end
Not enough input arguments.
Error in Mass_On_Stick_012345678 (line 3)
b=parameter(1);m=parameter(2);R=parameter(3);G=parameter(4);g=parameter(5);
2 commentaires
Star Strider
le 21 Jan 2020
First, your ODE function must return one vector, not two, so create one column vector from ‘dw’ and ‘ds’. (I leave that detail to you, however the original ‘w’ and ‘s’ values need to be a single column vector (I call it ‘ws’ here) and match the single column vector for the derivatives. The first argument also needs to be the independent variable (whatever variable the differential equations are differentiated with respect to, such as time).
Second, you need the ode45 call to it to be:
@(t,ws) Mass_On_Stick_012345678(t,ws,parameter)
with the ‘parameter’ vector existing in your workspace.
I am not listing this as an Answer because it is not one.
Réponse acceptée
James Tursa
le 21 Jan 2020
Try changing this
[t,y]=ode45('Mass_On_Stick_012345678',tSpan,y0,opts,Parameter);
to this
[t,y]=ode45(@(t,y)Mass_On_Stick_012345678(t,y,Parameter),tSpan,y0,opts);
4 commentaires
Walter Roberson
le 21 Jan 2020
The syntax for passing extra parameters by listing them at the end of the call, has been considered obsolete for 20 years.
Unless you need to program in MATLAB 4 or earlier, you should forget about passing function names as quoted strings and should switch over to function handle form.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!