Matlab第一次作業代碼

代碼如下:

clc,clear all                   
x1 = -20:0.01:20;
y1 = x1.^3 + 2*x1.^2 - 3*x1+4;

t = 0:0.01:2*pi;
r = cos(2.*t);

t = 0:0.01:2*pi;
x3 = (1+sin(t)-2.*cos(4*t)).*cos(t);
y3 = (1+sin(t)-2.*cos(4*t)).*sin(t);

x4 = -20:0.01:20;
y4 = sin(x4) + sin(2*x4);

figure('position',[600,150,700,700])
subplot(221)
plot(x1,y1,'r');
title('f(x)=x^{3}+2x^{2}-3x+4')
xlabel('x')
ylabel('f(x)')
grid on

subplot(222)
polar(t,r,'r');
title('r=cos2\Theta')

subplot(223)
plot(x3,y3);
title({'參數方程:';'x=(1+sint-2cos4t)cost';'y=(1+sint-2cos4t)sint'});
xlabel('x')
ylabel('y')
grid on

subplot(224)
plot(x4,y4);
title('y=sinx+sin2x')
xlabel('x')
ylabel('y')
grid on

    圖像如下:

 代碼如下:

function f = a_sqrt(a)
x = a;
f = (x+a./x)./2; 
while abs(f-x) > 0.00001
    x=f;
    f = (x+a./x)./2;
end

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章