フィルターのクリア

solving the pendulum differential equation with a for loop

1 回表示 (過去 30 日間)
federico midei
federico midei 2020 年 9 月 12 日
コメント済み: federico midei 2020 年 9 月 13 日
Hi I'm trying to write down a code that solves the equation of the pendulum in the hyp of little swings.
The task is to write it with a for loop without using the ODEs functions.
the code i wrote obviusly doesn't work.
Does someone could help me?
equation of pendulum:
l*diff(c,t,2)+g*c==0
code I wrote:
l=50; %rope length
g=9.81; %g constant
t=0; %time
syms c;
Dc= diff(c,t);
cond= [c(0)==0, Dc(0)==0.1]; %initial conditions
T=7.5*pi*sqrt(l/g);
n=linspace(0, T, 1000);
for i=1:n %I need the c value at every 't' from 0 to T with 1000 points
t= i;
ode = l*diff(c,t,2)+g*c==0;
sol=dsolve(ode,cond);
%sol=dsolve(ode);
end

採用された回答

BOB MATHEW SYJI
BOB MATHEW SYJI 2020 年 9 月 13 日
Hope this helps. The solution for the differential equation is obtained as cSol(t). The required solution is obtained as a row vector 'sol'
l=50; %rope length
g=9.81; %g constant
syms c(t);
Dc= diff(c,t);
ode = l*diff(Dc)+g*c==0;
cond=c(0)==0;
cond1=Dc(0)==0.1;
cSol(t)=dsolve(ode,[cond cond1]);
T=7.5*pi*sqrt(l/g);
n=linspace(0, T, 1000);
for i=1:length(n)
sol(i)=double(cSol(n(i)));
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by