matlab zad treningowe

Przykład 1.1

function[a,suma] = P_1_1(n)

a=zeros(n,1);

a(1)=4;

for i=2:1:n

a(i)=a(i-1)*(2*i-3)/(2*i-1);

end

suma=zeros(n,1);

suma(1)=a(1);

for i=2:1:n

suma(i)=suma(i-1)+a(i);

end

subplot(2,1,1),

plot(a,'o')

title('Elementy ciagu an')

xlabel('n')

ylabel('an')

subplot(2,1,2),

plot(suma,'o')

title('Ciag sum S')

xlabel('n')

ylabel('Sn')

end

Przykład 1.2

function[]= P_1_2;

y=[0:1:127,128*ones(1,128)];

z=fft(y);

subplot(2,1,1), plot(y)

subplot(2,1,2), stem(abs(z))

end

Przykład 1.3

function[]=P_1_3(n)

f=zeros(1,n);

g=zeros(1,n);

f(1)=1;

f(2)=1;

for i=3:1:n

f(i)=f(i-2)+f(i-1);

end

for i=1:1:n-1

g(i)=f(i+1)/f(i);

end

subplot(2,1,1), plot(f,'bo')

subplot(2,1,2), plot(g,'bo')

end

Przykład 1.4

function[]=P_1_4(n)

x=rand(1,n);

med=sum(x)/n;

sigma=0;

for i=1:1:n

sigma=sigma+(x(i)-med)^2;

end

sigma=sqrt(sigma/n);

y=[0:0.01:1]

plot(y,1/(sigma*sqrt(2*pi))*exp(-(y-med).^2/(2*sigma^2)))

end

Przykład 1.5

function[]=P_1_5(n)

for i=1:1:n

a(i)=1/i^3;

end

A=diag(a)

Przykład 1.6

function[]=P_1_6

x=[0:0.05:1+pi]

plot(x,sin(x)./x)

title('Wykres funkcji');

xlabel('x');

ylabel('f(x)');

q=max(sin(x)./x)

legend(num2str(q,10))

end

Przykład 1.7

function[]=P_1_7

x = 0:pi/20:pi;

y = 3./(1+sin(x));

plot(x,y)

title('Wykres funkcji');

xlabel('x');

ylabel('f(x)');

legend(num2str(min(y),10));

end

Przykład 1.8

function[]=P_1_8

x=1.1:0.05:2;

y=1./sqrt(x-1);

plot(x,y)

title('Wykres funkcji');

xlabel('x');

ylabel('f(x)');

legend(num2str(sum(y)/length(y)),10);

end

Przykład 1.9

function[]=P_1_9

x=1.1:0.05:3;

y=exp(x)./log(x);

plot(x,y)

title('Wykres funkcji');

xlabel('x');

ylabel('f(x)');

legend(num2str(sum(y)/length(y)),10);

end

Przykład 1.10

function[]=P_1_10

A=[3 -1 2;

1 2 3;

2 -2 -1];

B=[1;1;1];

X=A\B;

x=X(1)

y=X(2)

z=X(3)

end

Przykład 1.11

function[]=P_1_11

A=[2 5 3;

8 9 7;

4 6 1];

B=[9;12;18];

X=A\B;

x=X(1)

y=X(2)

z=X(3)

end

Przykład 1.12

function[]=P_1_12

A=[-1 5 2;

2 3 1;

3 2 1];

B=[-2;7;3];

X=A\B;

a=X(1)

b=X(2)

c=X(3)

end

Przykład 1.13

function[]=P_1_13

A=[4 12 8 4;

1 7 18 9;

2 9 20 20;

3 11 15 15];

B=[-4;-5;-25;-18];

X=A\B;

a=X(1)

b=X(2)

c=X(3)

d=X(4)

end

Przykład 1.14

function[]=P_1_14(x0)

x = fzero(@myfun,x0)

function f = myfun(x)

f = x^2-sqrt(3)*x-10;

end

end

Przykład 1.15

function[]=P_1_15(x0)

y = fzero(@myfun,x0)

function f = myfun(x)

f = x-sin(2*x)-3;

end

end

Przykład 1.16

function []=P_1_16

clear;clc;

x0 = [3; 1];

options=optimset('Display','iter');

[x,fval,flag] = fsolve(@myfun_16,x0,options)

End

Przykład 1.17

function[]=P_1_17

x0 = [3; 1];

options=optimset('Display','iter');

[x,fval] = fsolve(@myfun,x0,options)

function[F] = myfun(x)

F = [x(1)^2+4*x(2)^2-16;

x(1)*x(2)^2-4];

end

end

Przykład 1.18

function[]=P_1_18

x0 = [3; 2; 1];

options=optimset('Display','iter');

[x,fval] = fsolve(@myfun,x0,options)

function[F] = myfun(x)

F = [x(1)*x(2)*x(3)-1;

x(1)^2+x(2)^2+x(3)^2-4;

x(1)^2+2*x(2)^2-3];

end

end

Przykład 1.19

function[]=P_1_19

x0 = [1; 2; 3];

options=optimset('Display','iter');

[x,fval] = fsolve(@myfun,x0,options)

function[F] = myfun(x)

F = [x(1)^2+2*x(2)^2+4*x(3)^2-7

2*x(1)^2+x(2)^3+6*x(3)^2-10;

x(1)*x(2)*x(3)-1];

end

end

Przykład 1.20

function[]=P_1_20

x=1:0.1:pi;

y=sin(x)./x;

metoda_trapezow=trapz(x,y)

metoda_quadl=quadl(@(x)(sin(x)./x),1,pi)

end

Przykład 1.21

function[]=P_1_21

x=0:0.1:pi/2;

y=1./(1+sin(x));

metoda_trapezow=trapz(x,y)

metoda_quadl=quadl(@(x)(1./(1+sin(x))),0,pi/2)

end

Przykład 1.22

function[]=P_1_22

x=0:0.1:pi;

y=sin(x);

metoda_trapezow=trapz(x,y)

metoda_quadl=quadl(@(x)sin(x),0,pi)

end

Przykład 1.23

function[]=P_1_23

x=0:0.1:pi;

y=sqrt(1+cos(x));

metoda_trapezow=trapz(x,y)

metoda_quadl=quadl(@(x)sqrt(1+cos(x)),0,pi)

end

Przykład 1.24

function[]=P_1_24

x=0:0.1:2;

y=sqrt(1+exp(x).^2);

metoda_trapezow=trapz(x,y)

metoda_quadl=quadl(@(x)sqrt(1+exp(x).^2),0,2)

end

Przykład 1.25

function [t,y] = P_1_25

tspan = [0 2];

y0 = [2; 0];

% Call the ODE solver ode15s.

[t,y] = ode45(@vdp,tspan,y0);

plot(t,y,'-');

legend('f(x)','df/dt(x)')

function dydt = vdp(t,y)

dydt = [y(2); t+y(1)];

end

end

Przykład 1.26

function [t,y] = P_1_26

tspan = [0 2];

y0 = [1; 0.5];

% Call the ODE solver ode15s.

[t,y] = ode45(@vdp,tspan,y0);

plot(t,y,'-');

legend('f(x)','df/dt(x)')

function dydt = vdp(t,y)

dydt = [y(2); t+y(1)-3*y(2)];

end

end

Przykład 1.27

function [t,y] = P_1_27

tspan = [0 1];

y0 = [1; -2];

[t,y] = ode45(@f_prawe,tspan,y0);

plot(t,y,'-');

legend('f(x)','df/dt(x)')

function dydt = f_prawe(t,y)

dydt = [y(2); -y(2)+6*y(1)];

end

end

Przykład 1.28

function [t,y] = P_1_28

tspan = [0 2];

y0 = [1; -2];

[t,y] = ode45(@f_prawe,tspan,y0);

plot(t,y,'-');

legend('f(x)','df/dt(x)')

function dydt = f_prawe(t,y)

dydt = [y(2); y(2)/(1+t)+3*y(1)/(1+t)];

end

end


Wyszukiwarka

Podobne podstrony:
Matlab Zad 6 I13
ZAD-LAB-4-przewodnik, Zad. 1 (Num.Methods using Matlab, 1.3.1 (a))
STRUKTURA TRENINGU
Matlab cw1 2 zaoczni
Zasady przeprowadzania treningu
wm 2011 zad 2
cz 1, Matlab moj
prezentacja slajdy trening zastepowania agresji(1)
Struktura treningu sportowego (makrocykl) szkoła PZPN
Image Processing with Matlab 33
środki treningowe w rehabilitacji
Trening pływacki na lądzie
Mikroekspresje trening
Treningi antystresowe
Trening WOZPN

więcej podobnych podstron