You are on page 1of 2

Name: Ong Yi Han

ID: I17013478

Exercise 4

No Comment Editor Output


.
1. >> edit x=linspace(-2,2); 5

>> for r=1:5


4.5
y=r*exp(-(x.^2));
script_file plot(x,y) 4

hold on 3.5

end 3

hold off 2.5

1.5

0.5

0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2

2.( >> edit function z=mstar(n) 1

a) >> mstar(12) t=(0:pi/n:2*pi); 0.8


r=ones(size(t));
r(2:2:end)=0.4; 0.6

x=r.*cos(t); 0.4

y=r.*sin(t); 0.2

plot(x,y) 0

axis equal -0.2

-0.4

-0.6

-0.8

-1
-1 -0.5 0 0.5 1

3. >> edit function z =triangle(a,b,c) A=


>> s=(a+b+c)/2;
A=sqrt(s*(s-a)*(s-b)*(s-c))
triangle(3,5, 6.4952
7)
4. >> edit function z =
>> olympic(a,b,r,color_code)
t = linspace(0,3*pi); 2
olympic(0,0, x = a+cos(t);
1,'b') y = b+sin(t); 1

>> hold on plot(x,y,'Linewidth',8,'color',


0
>> color_code)
olympic(3,0, axis equal
-1

1,'k')
>> -2

olympic(6,0, -3
1,'r')
>> -1 0 1 2 3 4 5 6 7

olympic(1.5,
-1,1,'y')
>>
olympic(4.5,
-1,1,'g')

You might also like