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 个评论

Show your attempts
Hi Darova, this is my first attempt, but I am having trouble correctly writing the function, what do you think?
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

请先登录,再进行评论。

 采纳的回答

darova
darova 2020-5-27

0 个投票

I have some suggestions

4 个评论

Edinson Manga
Edinson Manga 2020-5-27
编辑:darova 2020-5-27
a few hours ago I saw my mistake and that's how I tried
Did it work? What about 'k'?
Edinson Manga
Edinson Manga 2020-5-27
编辑:darova 2020-5-27
replace that K with a For i=0:1:10
i think it works

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by