how can i bring 2 figures together?

1 view (last 30 days)
furkan aktürk
furkan aktürk on 29 Dec 2021
Edited: KSSV on 29 Dec 2021
clc
clear
x = [0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5];
y = 2+exp((-x).^3);
plot(x,y)
clc
clear
x (1)= 0;
y (1)= 3;
h = 0.05;
for i = 1:10
y (i+1)= y(i)+(6*x(i)^2-3*x(i)^2*y(i));
x (i+1)= x(i)+h;
end
plot(x,y,'-')
xlabel('x')
ylabel('y')
i want to show these two codes graphs in one figure. how can i do it ? btw x of two y are same but i couldnt use for different folder.

Accepted Answer

DGM
DGM on 29 Dec 2021
If you look, the two x vectors are not the same. They differ in length by 1. You can reuse the latter x if you want. Either way, you can plot mutliple things in an axes using hold.
x(1) = 0;
y2(1) = 3;
h = 0.05;
for i = 1:10
y2(i+1) = y2(i)+(6*x(i)^2-3*x(i)^2*y2(i));
x(i+1) = x(i)+h;
end
y1 = 2+exp((-x).^3);
plot(x,y1,'-'); hold on
plot(x,y2,'-')
xlabel('x')
ylabel('y')

More Answers (1)

KSSV
KSSV on 29 Dec 2021
Edited: KSSV on 29 Dec 2021
Read about hold on.
clc
clear
x1 = [0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5];
y1 = 2+exp((-x1).^3);
plot(x1,y1)
hold on
x (1)= 0;
y (1)= 3;
h = 0.05;
for i = 1:10
y (i+1)= y(i)+(6*x(i)^2-3*x(i)^2*y(i));
x (i+1)= x(i)+h;
end
plot(x,y,'-')
xlabel('x')
ylabel('y')
legend({'data1','data2'})

Community Treasure Hunt

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

Start Hunting!