如何在一个图上绘制两个函数? [英] How to plot two functions on one graph?

查看:235
本文介绍了如何在一个图上绘制两个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了作业,在一张图中绘制函数x ^ 3和3 ^ x。

有没有人可以帮我做这个练习?

解决方案

每次调用 plot 这个新的函数,除非你专注于一个叫的窗口,这将基本上告诉Matlab保留旧的东西并叠加新的绘图。

  x = 0:0.001:10 

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

plot(x,y1);
坚持;没有这个的%将在绘制之前删除y1
plot(x,y2,'r');


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?

解决方案

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');

这篇关于如何在一个图上绘制两个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆