MATLAB 绘制基本初等函数图像

内容纲要

环境

MATLAB R2022b

代码

注:
要对矩阵中的每个元素分别计算时,运算符前加一个点 “.”;
绘制图像可以使用 MATLAB 内置的函数,如 fplot(表达式和函数)、fimplicit(绘制隐函数),也可以自己生成一个 x 的矩阵,再计算得到 y 的值的矩阵,最后使用 plot 绘制。

代码文本

x1 = linspace(-10, 10, 10000);
x2 = linspace(0, 5, 5000);

y = x1 .^ 2;
plot(x1, y);
title('y=x^2');

y = x2 .^ 0.5;
plot(x2, y);
title('y=x^{0.5}');

y = 1.1 .^ x1;
plot(x1, y);
title('y=1.1^x');

y = 0.9 .^ x1;
plot(x1, y);
title('y=0.9^x');

y = log(x2) ./ log(1.001);
plot(x2, y);
title('y=log_{1.001}x');

y = log(x2) ./ log(0.009);
plot(x2, y);
title('y=log_{1.001}x');

fplot(@(x)sin(x));
title('y=sin x');

fplot(@(x)cos(x));
title('y=cos x');

fplot(@(x)tan(x));
title('y=tan x');

fplot(@(x)sec(x));
title('y=sec x');

fplot(@(x)csc(x));
title('y=csc x');

fplot(@(x)cot(x));
title('y=cot x');

fplot(@(x)asin(x));
title('y=arcsin x');

fplot(@(x)acos(x));
title('y=arccos x');

fplot(@(x)atan(x));
title('y=arctan x');

fplot(@(x)asec(x));
title('y=arcsec x');

fplot(@(x)acsc(x));
title('y=arccsc x');

fplot(@(x)acot(x));
title('y=arccot x');

代码截图
file
file
file
file
file
file
file

绘图结果

file
file
file
file
file
file
file
file
file
file
file
file
file
file
file
file
file
file