what is the wrong here

1 Ansicht (letzte 30 Tage)
jake carl
jake carl am 24 Dez. 2020
Beantwortet: William am 24 Dez. 2020

Antworten (2)

David Hill
David Hill am 24 Dez. 2020
h=.25;
t=0:h:1;
y=zeros(size(t));
y(1)=.1;%cannot start with y=0
f=@(t,y)(1+4*t)*sqrt(y);%I assume this is what you want
for i=1:length(t)-1
y(i+1)=y(i)+h*f(t(i),y(i));
end
plot(t,y);
grid on;

William
William am 24 Dez. 2020
David is probably right, but I made a different assumption about what equation you were trying to solve:
h = 0.25;
x = 0:h:1;
y = zeros(size(x));
y(1)=0;
n = numel(y);
t = 2;
for i=1:n-1
f = (1+4*t)*sqrt(x(i));
y(i+1)=y(i)+h*f;
end
plot(x,y);
grid on;

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by