Hi, i need to solve the differential equation of my pendulum, but when i type my code, Matlab marks me a problem in my M-file. Hope you can help me, please!
m-file
function dudt=pendulum (t,u)
w=10;
dudt(1,:) = u(2);
dudt(2,:) = -w*sin(u(1));
end
The code is the netx one
tspan=[0,2*pi];
u0=[pi/4;0];
[t,u]=ode45(@pendulum,tspan,u0,[]);
plot(t,u(:,1),'b-', 'Line Width', 2)
xlabel('time')
ylabel('angle')

 採用された回答

Star Strider
Star Strider 2020 年 5 月 16 日

1 投票

Eliminate the space:
plot(t,u(:,1),'b-', 'Line Width', 2)
↑ ← HERE
It should be:
plot(t,u(:,1),'b-', 'LineWidth', 2)
That willl work.

4 件のコメント

Carlos Gerardo Rodríguez González
Carlos Gerardo Rodríguez González 2020 年 5 月 16 日
It works, thank you very much!!
Star Strider
Star Strider 2020 年 5 月 16 日
As always, my pleasure!
KLETECH MOTORSPORTS
KLETECH MOTORSPORTS 2020 年 11 月 3 日
KLETECH MOTORSPORTS
KLETECH MOTORSPORTS 2020 年 11 月 3 日
i got ^ error when i ran the code

サインインしてコメントする。

その他の回答 (1 件)

John D'Errico
John D'Errico 2020 年 5 月 16 日

1 投票

Why do you think there is a problem? The code runs fine.
Are you worried that the editor tells you that essentially, t is not used as a variable? That is just a warning, in case you have made a mistake.
Is that the correct sytem of ODEs? If so, then there is no problem.

2 件のコメント

Carlos Gerardo Rodríguez González
Carlos Gerardo Rodríguez González 2020 年 5 月 16 日
Hi, yes, when i type my m-file, Matlab signs me this problems, i can't put the two variables in my ODE
Carlos Gerardo Rodríguez González
Carlos Gerardo Rodríguez González 2020 年 5 月 16 日
Sorry, ma mistake, it works, i restart my pc and works, thank you for your suppor!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Programming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by