フィルターのクリア

Matlab plot is not correct

1 回表示 (過去 30 日間)
주선 문
주선 문 2022 年 8 月 25 日
回答済み: Chunru 2022 年 8 月 25 日
clc,clear;close all;
f = @(t,y,s) (0.0012*((1-y)/(1.66*10^(6)))+s-0.0012*0.02*y); %y=Nddotexi,vmed=0.02,fdot=3*10^(-18),r=0.0012,k=Nsurv
a = 0; %input('initial ponit, a: ');
b = 100; %input('end point, b: ');
n = 10; %input('intervals, n: ');
alpha = 0; %input('initial condition, alpha: ');
h = (b-a)/n;
t=[a zeros(1,n+1)];
y=[alpha zeros(1,n+1)];
s=[0 zeros(1,n+1)];
for i = 1:n+1
t(i+1)=t(i)+h;
yprime=y(i)+h*f(t(i),y(i),s(i)); %slope
y(i+1)=y(i)+h*f(t(i+1),yprime,s(i+1));
fprintf('%.4f %.4f\n', t(i), y(i));
figure(1)
plot(t(i),y(i),'r-o');
xlabel('t values'); ylabel('y values');
grid on; hold on;
legend('y')
end
Plot dont consist line
How can i fix it?

採用された回答

Chunru
Chunru 2022 年 8 月 25 日
f = @(t,y,s) (0.0012*((1-y)/(1.66*10^(6)))+s-0.0012*0.02*y); %y=Nddotexi,vmed=0.02,fdot=3*10^(-18),r=0.0012,k=Nsurv
a = 0; %input('initial ponit, a: ');
b = 100; %input('end point, b: ');
n = 10; %input('intervals, n: ');
alpha = 0; %input('initial condition, alpha: ');
h = (b-a)/n;
t=[a zeros(1,n+1)];
y=[alpha zeros(1,n+1)];
s=[0 zeros(1,n+1)];
for i = 1:n+1
t(i+1)=t(i)+h;
yprime=y(i)+h*f(t(i),y(i),s(i)); %slope
y(i+1)=y(i)+h*f(t(i+1),yprime,s(i+1));
fprintf('%.4f %.4f\n', t(i), y(i));
end
0.0000 0.0000 10.0000 0.0000 20.0000 0.0000 30.0000 0.0000 40.0000 0.0000 50.0000 0.0000 60.0000 0.0000 70.0000 0.0000 80.0000 0.0000 90.0000 0.0000 100.0000 0.0000
figure(1)
plot(t,y,'r-o');
xlabel('t values'); ylabel('y values');
grid on;
legend('y')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by