用matlab绘制函数图像

1.一元函数

比如 f(x)=x+10sin(5x)+7cos(4x)

%%%%%%%%%f(x)=x+10sin(5x)+7cos(4x)%%%%%%%%%%
clear all;              %清除所有变量
close all;              %清图
clc;                    %清屏
x=0:0.01:10;
y=x+10*sin(5*x)+7*cos(4*x);
plot(x,y)
xlabel('x')
ylabel('f(x)')
title('f(x)=x+10sin(5x)+7cos(4x)')

结果

2.二元函数

比如f(x,y)=3cos(xy)+x+y

%%%%%%%%%f(x,y)=3cos(xy)+x+y%%%%%%%%%%
clear all;              %清除所有变量
close all;              %清图
clc;                    %清屏
x=-4:0.02:4;
y=-4:0.02:4;
N=size(x,2);
for i=1:N
    for j=1:N
         z(i,j)=3*cos(x(i)*y(j))+x(i)+y(j);
    end
end
mesh(x,y,z)
xlabel('x')
ylabel('y')

结果

比如f(x,y)=-((x^2+y-1).^2+(x+y^2-7)^2)/200+10

%%%%%%%%f(x,y)=-((x^2+y-1).^2+(x+y^2-7)^2)/200+10%%%%%%%%
clear all;              %清除所有变量
close all;              %清图
clc;                    %清屏
x=-100:1:100;
y=-100:1:100;
N=size(x,2);
for i=1:N
    for j=1:N
        z(i,j)=-((x(i)^2+y(j)-1).^2+(x(i)+y(j)^2-7)^2)/200+10;
    end
end
mesh(x,y,z)
xlabel('x')
ylabel('y')

结果

(1)多条曲线画在同一个图像里

tip:使用 hold on 函数

t=[0:0.01:1];
q1=120-180*t.^2+120*t.^3;
q2=120-600*t.^3+900*t.^4-360*t.^5;
plot(t,q1);hold on;
plot(t,q2); 

结果

增加图例

利用l egend 函数

t=[0:0.01:1];
q1=120-180*t.^2+120*t.^3;
q2=120-600*t.^3+900*t.^4-360*t.^5;
plot(t,q1,'r'); hold on;
plot(t,q2,'b');
legend('a)函数图像','b)函数图像')  %要按函数的顺序来添加

参考文献

https://blog.csdn.net/weixin_42279993/article/details/89401523

  • 71
    点赞
  • 586
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值