How make the map of integral curves in the region [0, 10] × [0, 10] of the differential equation y′(t) = (y (t) - 5) (cos2 (t) - 0.5) graphing simultaneously, for k = 0, 1,. . . , 10, the solution obtained using Euler's method with step h = 0.01 and with initial condition y (0) = k.

3 commentaires

darova
darova le 26 Mai 2020
Show your attempts
Edinson Manga
Edinson Manga le 26 Mai 2020
Hi Darova, this is my first attempt, but I am having trouble correctly writing the function, what do you think?
Edinson Manga
Edinson Manga le 26 Mai 2020
H = [0.01];
Y_euler = cell(1,numel(H));
for j=1:numel(H)
h = H(j);
x = 0:h:10;
y = zeros(1, numel(x));
y(1) = 1;
n = numel(y);
for i=1:n-1
f = ((y(x)-5)*(cos(x)^2)-0.5));
y(i+1) = y(i) + h * f;
end
Y_euler{j} = [x; y].';
end
syms Y(X)
eq = diff(Y) == (Y-5)*(cos.^2)-0.5));
for i=0:10
ic = Y(0) == i;
i=i+1;
sol = dsolve(eq, ic);
y_sol = double(subs(sol, X, x));
hold on
plot(x, y_sol, 'r', 'DisplayName', 'true solution');
for k=1:numel(H)
plot(Y_euler{j}(:,1), Y_euler{j}(:,2), 'b--', 'DisplayName', ['Euler method h=' num2str(H(k), '%.3f')]);
end
end

Connectez-vous pour commenter.

 Réponse acceptée

darova
darova le 27 Mai 2020

0 votes

I have some suggestions

4 commentaires

Edinson Manga
Edinson Manga le 27 Mai 2020
Modifié(e) : darova le 27 Mai 2020
Edinson Manga
Edinson Manga le 27 Mai 2020
a few hours ago I saw my mistake and that's how I tried
darova
darova le 27 Mai 2020
Did it work? What about 'k'?
Edinson Manga
Edinson Manga le 27 Mai 2020
Modifié(e) : darova le 27 Mai 2020
replace that K with a For i=0:1:10
i think it works

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by