Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

matlab - How to plot two functions on one graph?

I've been given the homework to graph the function x^3 and 3^x in one graph.

Does anyone could help me with this exercise please?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

every time you call plot matlab will clean the canvas before drawing the new function, unless you are focused on a window where you called hold on, which will substantially tells Matlab to keep the old stuff and superimpose the new drawing.

x = 0:0.001:10

y1 = x.^3;
y2 = 3.^x;

plot(x, y1);
hold on; % without this one will delete y1 before drawing y2
plot(x, y2, 'r');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...