matlab程序设计和符号运算题目

img

img

你好同学,代码供参考:
第1题

function [v1,v2,v3,v4] = fun1(x)
v1 = exp(x);
v2 = log(x);
v3 = sin(x);
v4 = cos(x);
end

示例

[v1,v2,v3,v4] = fun1(1-1i)

v1 =

   1.4687 - 2.2874i


v2 =

   0.3466 - 0.7854i


v3 =

   1.2985 - 0.6350i


v4 =

   0.8337 + 0.9889i

第2题

function [a1,a2,N1,N2] = fun2()
m1 = input('m1: ');
m2 = input('m2: ');
theta = input('theta: ');
g=9.8;
x = [m1*cos(theta), -m1, -sin(theta),0; m1*sin(theta),0,cos(theta),0; 
    0,m2,-sin(theta),0; 0,0,-cos(theta),1]\[0;m1*g;0;m2*g];
a1 = x(1);
a2 = x(2);
N1 = x(3);
N2 = x(4);
end

输出结果:

[a1,a2,N1,N2] = fun2()
m1: 1
m2: 1
theta: 1

a1 =

    9.6558


a2 =

    2.6085


N1 =

    3.1000


N2 =

   11.4749

第三题

function fun3(x)
if(nargin==0)
    fplot(@(x)square(x*2*pi),[0,4.5]); axis off;
elseif(x==1)
    fsurf(@(x,y)x.^2.*exp(-(x.^2+y.^2)), [-2,2,-2,2]);
elseif(x==2)
    fimplicit(@(x,y)1-x.^2-y.^2, [-2,2,-2,2]); axis equal
elseif(x==3)
    fplot(@(x)sin(x), [0,4*pi])
end
end

主函数

clc;clear
figure(1);clf
subplot(2,2,1)
fun3()
subplot(2,2,2)
fun3(1)
subplot(2,2,3)
fun3(2)
subplot(2,2,4)
fun3(3)

img

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632