Coding a solution to a second order ODE with ode45 or simulink

Please help! y''+by'+siny=0 -Plot the numerical solution of this differential equation with initial conditions y(0)=0, y'(0)=4, from t=0 to t=20 -Do the same for the linear approximation y''+by'+y=0 -Compare linear and nonlinear behavior for values b = 1, 1.5, 2

2 件のコメント

madhan ravi
madhan ravi 2018 年 10 月 22 日
Upload your code
Alex Patterson
Alex Patterson 2018 年 10 月 22 日
syms t f
function fprime = pendulum(t, f) b = [1, 1.5, 2]; fprime = zeros(size(f)); fprime(1) = f(2); fprime(2) = -sin(f(1))-b*f(2); [t f] = ode45('pendulum', [0 20], [0 4]); plot(t,f(:,1)) end

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

 採用された回答

madhan ravi
madhan ravi 2018 年 10 月 22 日
編集済み: madhan ravi 2018 年 10 月 22 日

1 投票

[t,f] = ode45(@pendulum, [0 20], [0 4]); % calling of the function
plot(t,f(:,1),'g')
hold on
plot(t,f(:,2),'r')
function fprime = pendulum(t, f)
b = 1; % b should be a scalar
fprime = zeros(size(f));
fprime(1) = f(2);
fprime(2) = -sin(f(1))-b*f(2);
fprime=[fprime(1);fprime(2)]
end

3 件のコメント

madhan ravi
madhan ravi 2018 年 10 月 22 日
編集済み: madhan ravi 2018 年 10 月 22 日
If something is not clear let know else accept the answer so that people know the question is solved
Alex Patterson
Alex Patterson 2018 年 10 月 22 日
Is there a way I can plot a second equation on the same graph? Thank you.
madhan ravi
madhan ravi 2018 年 10 月 22 日
see edited

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

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by