Plotting a graph with given points
1 回表示 (過去 30 日間)
古いコメントを表示
I have created a function to compute the Euler of a given IVP as seen below:
function U= Uler(N,h,y)
t = 0;
S = N/h;
for i=1:S
y = y +(h*(0.5*y*(1-y/2)))
t = t +h
end
U=y
end
My question is how do I plot a graph using the values of t and y I obtained during this function?
0 件のコメント
回答 (1 件)
KSSV
2017 年 11 月 13 日
function [t,y]= Uler(N,h,y)
S = N/h;
y = zeros(1,S) ;
t = zeros(1,S) ;
% initial condition
y(1) = 0 ;
t(1) = 0 ;
for i=2:S
y(i) = y(i-1) +(h*(0.5*y*(1-y/2))) ;
t(i) = t(i-1) +h
end
end
[t,y]= Uler(N,h,y) ;
plot(t,y) ;
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!