Professional Documents
Culture Documents
Vježba 3 Modeliranje I Simuliranje
Vježba 3 Modeliranje I Simuliranje
if nargin == 2
s = x + y;
else
s = x + y +z;
end % U editor napišemo funkciju te ju testiramo
>> zbroji (5,4,3)
ans =
12
Pozivanje s promjenjivim brojem argumenta
function s = zbroji_nova(varargin)
if ~isnumeric([varargin{ :}])
error('Ulazi moraju biti numeričke vrijednosti.')
end
s = sum([varargin{ :}]);
>> zbroji_nova(5,4,6,2,3)
ans =
20
function y=sumcuberoots(x)
y=sum(cuberoot(x)); function z
= cuberoot(x)
z = sign(x).*abs(x).^(1/3);
>sumcuberoots(9)
ans =
2.0801
function pr1_6_1=pr1_6_1()
t=[0_10/1000.10]’;
for i=1:5
y(:,i)1-exp(-2*t/i).*cos(2*pi/2*t);
end
t %ispiši t
y %ispiši y
xlabel(‘t[s]’) %x os
ylabel(‘y(t)’) %y os
>> pr1_6_1()
t=
0.0100
0.0200
0.0300
0.0400
…
9.9800
9.9900
10.0000
y=
0 0 0 0 0
… … … … …
>> xlabel('t[s]')
>> ylabel('y(t)')
>> oznake(1)
>> legend(1)
>> t=[0:10/1000:10]';
for i=1:5
y(:,i)=1-exp(-2*t/i).*cos(2*pi/2*t);
end
>> semilogx(t,y)
>> oznake(1)
ans =
oznaka =
Columns 1 through 2
Columns 3 through 4
Column 5
{'Konstanta prigu…'}
>> subplot(2,2,3)
>> xlabel('t[s]')
>> semilogx(t,y)
>> semilogy(t,y)
>> subplot(2,2,1)
>> xlabel('t[s]')
>> ylabel('y(t)')
>> subplot(2,2,3)
>> grid
>> subplot(2,2,3)
>> grid
>> grid
>> subplot(2,2,1)
>> grid
>> subplot(2,2,3)
>> ylabel('y(t)')
>> xlabel('t[s]')
>> subplot(1,2,2)
>> plot(t,y)
>> xlabel('t[s]')
>> ylabel('y(t)')
>> legend(oznaka)
>> grid
Prikaz funkcije malim brojem točaka
>> t=[0:10/7:10]'
t=
1.4286
2.8571
4.2857
5.7143
7.1429
8.5714
10.0000
>> y1=2-sin(t);
>> subplot(2,2,1),plot(t,y1,'r');
>> grid
>> xlabel('t(s)')
>> title('plot(t,y1,"r")')
>> subplot(2,2,2),stem(t,y1,'b:')
>> grid
>> xlabel('t(s)')
>> title('stem(t,y1,"b:")')
>> subplot(2,2,3),stairs(t,y1,'g.-')
>> grid
>> xlabel('t(s)')
>> title('stairs(t,y1,"g.-")')
>> subplot(2,2,4),bar(t,y1,'c')
>> grid
>> xlabel('t(s)')
>> title('bar(t,y1,"c")')
th =
>> r=2*th
r=
>> polarplot(th,r,'r')
function pr1_6_5=pr1_6_5()
t=[0:2*pi/1000:2*pi]';
x=t.*cos(6*t);
y=t.*sin(6*t);
for i=1:4
end
plot3(x,y,z)
grid
legend(opis)
xlabel('x')
ylabel('y')
zlabel('z')
>> pr1_6_5()
Generiranje 2D mreže
>> x1=1:5;
>> y1=1:3;
>> [x,y]=meshgrid(x1,y1)
x=
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
y=
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
Iscrtavanje 3D plohe
>> x1=linspace(-2,2,100)
x1 =
>> y1=linspace(-2,2,100)
y1 =
>> [x,y]=meshgrid(x1,y1)
x=
>> z=sin(x.^2+y.^2)
z=
Columns 1 through 7
ssdsd
>> surf (x,y,z)