what wrong in my code when i use ode 45,and what the error are mean
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Star Strider
2020-1-21
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.
采纳的回答
James Tursa
2020-1-21
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 个评论
Walter Roberson
2020-1-21
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!