ode45 or dsolve

6 ビュー (過去 30 日間)
felik kamwera
felik kamwera 2019 年 6 月 24 日
コメント済み: felik kamwera 2019 年 6 月 24 日
whats wrong with my code.. its from a book but cant run
tspan=[0 4];
y0=[0.02;0];
[t,y]=ode45('unforced1',tspan,y0);
plot(t,y(:,1));
grid on
xlabel(time)
ylabel(Displacement)
title(Displacement Vs Time)
hold on;
its function is function yp = unforced1(t,y)
yp = [y(2);(-((c/m)*y(2))-((k/m)*y(1)))];
  4 件のコメント
Chinmay Anand
Chinmay Anand 2019 年 6 月 24 日
What are c and m defined in your function ? Have you assigned any values to them ?
felik kamwera
felik kamwera 2019 年 6 月 24 日
should i give them values in the function definition or call?

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

採用された回答

madhan ravi
madhan ravi 2019 年 6 月 24 日
tspan=[0 4];
y0=[0.02;0];
m=5;
k=1000;
c=1000;
[t,y]=ode45(@(t,y)unforced1(t,y,c,m,k),tspan,y0); % function call
plot(t,y(:,1));
grid on
xlabel('time')
ylabel('Displacement')
title('Displacement Vs Time')
%function definition
function yp = unforced1(t,y,c,m,k) % if your version is prior to 2016b save this in a separate file name unforced1.m
yp = [y(2);
(-((c/m)*y(2))-((k/m)*y(1)))];
end
  1 件のコメント
felik kamwera
felik kamwera 2019 年 6 月 24 日
thank u very much...i have seen where i was wrong..again thank u

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

その他の回答 (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