Error as Function definitions are not permitted in this context.
2 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I am getting error as Function definitions are not permitted in this context.
My code:
function dydt = odefcn(t,y,A,B)
dydt = zeros(2,1);
dydt(1) = y(2);
dydt(2) = (A/B)*t*y(1);
A= 1;
B= 2;
tspan=[0 5];
y0 = [0 0.01];
[t,y]= ode15s(@(t,y) odefcn(t,y,A,B), tspan, y0);
plot(t,y(:,1),'-o',t,y(:,2),'-.' )
Could you please help me.
0 件のコメント
採用された回答
KSSV
2017 年 4 月 4 日
You have two options:
function Main
A= 1;
B= 2;
tspan=[0 5];
y0 = [0 0.01];
[t,y]= ode15s(@(t,y) odefcn(t,y,A,B), tspan, y0);
plot(t,y(:,1),'-o',t,y(:,2),'-.' )
end
function dydt = odefcn(t,y,A,B)
dydt = zeros(2,1);
dydt(1) = y(2);
dydt(2) = (A/B)*t*y(1);
end
Save the above lines in the m file and name it Main.m and run.
Or save the odefcn function alone in as function in file odefcn.m and call it file.
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!