Function call in ode45 does not work?
1 回表示 (過去 30 日間)
古いコメントを表示
I have function:
function [f,R]=fun_zap_ri_07(z,p)
beta=1;
ri=0.7;
R=ri-z.*(ri-1);
f=zeros(4,size(p,2));
f(1,:)=-32.*beta./(R.^4.*p(1,:));
f(2,:)=(-8*f(1,:)./R-f(1,:).*p(2,:))./p(1,:);
f(3,:)=(-p(2,:).*f(2,:)-8.*f(2,:)./R-8.*f(1,:)./(R.*R.*p(1,:))-f(1,:).*p(3,:))./p(1,:);
f(4,:)=(-f(2,:).*p(3,:)-f(3,:).*p(2,:)+8.*(-f(3,:)./R- (f(2,:)./p(1,:)-p(2,:).*f(1,:)./(p(1,:).*p(1,:)))./(R.*R)) -f(1,:).*p(4,:))./p(1,:);
which I am calling with
beta = 1;
z = linspace(1, 0, 101);
ri = 0.7;
R = ri - z .* (ri - 1);
[zv, pv] = ode45(@fun_zap_ri_07, z, [1; 0; 0; 0], options);
I need to put beta nad ri values in function definition, it means I need to have the same function as above, just with:
function [f,R]=fun_zap_ri_07_beta(z,p,beta,ri)
R=ri-z.*(ri-1);
f=zeros(4,size(p,2));
f(1,:)=-32.*beta./(R.^4.*p(1,:));
f(2,:)=(-8*f(1,:)./R-f(1,:).*p(2,:))./p(1,:);
f(3,:)=(-p(2,:).*f(2,:)-8.*f(2,:)./R-8.*f(1,:)./(R.*R.*p(1,:))-f(1,:).*p(3,:))./p(1,:);
f(4,:)=(-f(2,:).*p(3,:)-f(3,:).*p(2,:)+8.*(-f(3,:)./R- (f(2,:)./p(1,:)-p(2,:).*f(1,:)./(p(1,:).*p(1,:)))./(R.*R)) -f(1,:).*p(4,:))./p(1,:);
which I am calling with
z = linspace(1, 0, 101);
[zv, pv] = ode45(@fun_zap_ri_07_beta, z, [1; 0; 0; 0], 1, 0.7, options);
but it does not work. Error message is:
Undefined operator '-' for input arguments of type 'struct'.
Error in fun_zap_ri_07_beta (line 9)
R=ri-z.*(ri-1);
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
0 件のコメント
回答 (1 件)
Alex Pedcenko
2019 年 9 月 27 日
編集済み: Alex Pedcenko
2019 年 9 月 27 日
it looks like there are not enough arguments to ode45
[t,y] = ode45(odefun,tspan,y0)
if you give odefun and all 4 inputs to your odefun, but not last 2 parameters tspan and y0, which are not passed to odefun.
It then "thinks" that tspan is your "options" and produces that error (options is "struct")
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!