Plotting using fimplicit and plot in the same figure
Show older comments
I copied my code below. The issue I am having is in the second figure. I want to plot two different curves/lines, one using fimplicit and the other using plot in the same figure. However, it only plots the fimplicit statement and seems to completely ignore the plot statement, despite the fact that it works fine in the first figure. I'm not sure what to do. I thought I was using hold on and hold off correctly. Any insights would be appreciated!
[t, y] = ode45(@(t,y) (t-exp(-t))/(y+exp(y)), [1.5 0], 0.5);
fprintf('\nWhen t = 0, y is approximately %d.\n', y(t == 0))
fprintf('When t = 1, y is approximately %d.\n', y(t < 1.02 & t > 0.98))
told = t;
yold = y;
[t, y] = ode45(@(t,y) (t-exp(-t))/(y+exp(y)), [1.5 2.1], 0.5);
fprintf('When t = 1.8, y is approximately %d.\n', y(t < 1.81 & t > 1.79))
fprintf('When t = 2.1, y is approximately %d.\n', y(t == 2.1))
t = [told t];
y = [yold y];
figure(1);
plot(t,y, 'r');
xlim([0 2.1]);
grid on
grid minor
hold off
syms z x
f(x, z) = 2*exp(z) + z^2 - 2*exp(-x) - x^2;
c = f(1.5, 0.5);
figure(2);
plot(t, y, 'rx');
hold on
fimplicit(f-c, [0, 2.1, -1, 2], 'b');
grid on
grid minor
hold off
Accepted Answer
More Answers (0)
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!