Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1.INTERPOLACJA LANGREGA
- clc
- clear
- xdel
- n=4
- X=[-2;-1.5;3;5]
- Y=[7;11;16;-1]
- a = zeros(n)
- for i = 1:n
- il=1
- for j = 1:n
- if i <> j
- il=il*(X(i)-X(j))
- end
- end
- a(i) = Y(i)/il
- end
- disp('a')
- disp(a)
- function [w] = W(z)
- fun = 0
- for i = 1:n
- il=1
- for j = 1:n
- if i <> j
- il = (z - X(j)).* il
- end
- end
- fun = fun + a(i)*il
- end
- w = fun
- endfunction
- disp('W(-0.5)')
- disp(W(-0.5))
- z = -3:0.1:6
- plot(X,Y,'redx')
- plot(z,W(z))
- plot(-0.5,W(-0.5),'greeno')
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!112.INTERPOLACJA WIELOMIANOWA
- clc
- clear
- xdel
- n=5
- x=[-3;-2;-0.5;1;3.5]
- y=[4;4.8;-1.2;7;13]
- X=zeros(5,5)
- m = size(X,"r")
- n = size(X,"c")
- for i=1:n
- for j=1:n
- X(i,j)=x(i)^(j-1)
- end
- end
- disp(X)
- a=inv(X)*y
- disp('wektor a:')
- for i=1:n
- disp(a(i))
- end
- function [w]=W(z)
- w=a(1)+a(2)*z+a(3)*z^2+a(4)*z^3+a(5)*z^4
- endfunction
- disp('wartosc dla 0.5:')
- Res1=W(0.5)
- disp(Res1)
- s=-4:0.1:4
- plot(s,W(s))
- plot(x,y, 'redx')
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1111113.NEWTON I WZOR
- clc
- clear
- xdel
- disp('I wzor Newtona:')
- n=6
- x=[0.8;1;1.2;1.4;1.6;1.8]
- y=[-3.52;-5;-6.72;-8.68;-10.88;-13.32]
- for i=1:n
- z(i,1)=x(i,1)
- z(i,2)=y(i,1)
- end
- disp(z)
- disp('tabela roznic:')
- for j=3:n+1
- for i=1:n-j+2
- z(i,j)=z(i+1,j-1)-z(i,j-1)
- end
- end
- disp(z)
- h=0.2
- s=1.3
- //k=z(3,1)
- k=3
- q=((1.3-z(k,1))/h)
- disp('q:')
- disp(q)
- function [w]=f(s)
- q=(s-x(k))/h
- w = z(k,2)+(z(k,3).*q)+(z(k,4).*(q.*(q-1))/2)+(z(k,5).*(q.*(q-1).*(q-2))/6)
- endfunction
- disp("W(s)=")
- disp(f(s))
- s=0.6:0.1:2
- plot(x,y,'redx')
- plot(s,f(s))
- !!!!!!!!!!!!!!!!!!!!!!!!!!11!!!!!!!!!!!!!!!!!!!!!!!!4.NEWTON II WZOR
- clc
- clear
- xdel
- disp("2 wzor newtona:")
- n=4
- x=[50;100;150;200]
- y=[-6.912;-7.605;-8.011;-8.298]
- for i=1:n
- z(i,1)=x(i,1)
- z(i,2)=y(i,1)
- end
- disp(z)
- disp('tabela roznic:')
- for j=3:n+1
- for i=1:n-j+2
- z(i,j)=z(i+1,j-1)-z(i,j-1)
- end
- end
- disp(z)
- h=50
- s=175
- //k=z(3,1)
- k=3
- q=((1.3-z(k,1))/h)
- disp('q:')
- disp(q)
- function [w]=f(s)
- q=(s-x(k))/h
- w = z(k,2)+(z(k-1,3).*q)+(z(k-2,4).*(q.*(q-1))/2)
- endfunction
- disp("W(s)=")
- disp(f(s))
- s=50:0.1:250
- plot(x,y,'redx')
- plot(s,f(s))
- !!!!!!!!!!!!!!1!!!!!!!!!!!!!!!!!!!!!!!!!!!15.GAUSS
- clc
- clear
- xdel
- a=2
- b=8
- z=0
- calka=0
- n=4
- ksi=[-0.86113;-0.339098;0.33998;0.86113]
- w=[0.34785;0.65214;0.65214;0.34785]
- function W1=f(z)
- W1=3.5*z^(1/2)
- endfunction
- function W2 = F(ksi)
- z =((b+a)/2)+((b-a)/2)*ksi
- W2 =((b-a)/2)*f(z)
- endfunction
- for i =1:(n)
- calka = calka + F(ksi(i))*w(i)
- end
- disp(calka)
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!6.PROSTOKATY
- clc
- clear
- xdel
- a = 2;
- b = 8;
- n = 1000;
- calka_pr = 0;
- function W = f(z)
- W = 3.5*z^(1/2)
- endfunction
- h = (b-a)/n
- for i =1:(n)
- x(i) = a + ((i-1) * h)
- calka_pr = calka_pr + (h * f(x(i)))
- end
- disp(calka_pr);
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1!!!!!!!!!!!7.TRAPEZY
- clc
- clear
- xdel
- a = 2;
- b = 8;
- n = 1000;
- calka_tr = 0;
- wynik = 0;
- x = zeros(n,1)
- y = zeros(n,1)
- function W = f(z)
- W = 3.5*z^(1/2)
- endfunction
- h = (b-a)/n
- for i =2:(n)
- x(i+1) = a + ((i-1)*h)
- y(i+1) = f(x(i+1))
- if(i>0)
- wynik = wynik + y(i+1)
- end
- end
- calka_tr = h*(((y(1)+y(n))/2) + wynik)
- disp(calka_tr)
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!8.KUBATURA GAUSSA
- clc
- clear
- xdel
- n=3
- i=0
- calka=0
- J=0
- n=3
- x=[1;3;1]
- y=[1;3;3]
- ksi=[0.5;0;0.5]
- eta=[0.5;0.5;0]
- wi=[1/3;1/3;1/3]
- function wynik=f(x,y)
- wynik=3*log(x)*(y^2+7)
- endfunction
- J=((x(2)-x(1))*(y(3)-y(1)))-((x(3)-x(1))*(y(2)-y(1)))
- disp(J)
- function wynik1=F(ksi,eta)
- wynik1=abs(J)*f(x(1)+(x(2)-x(1))*ksi+(x(3)-x(1))*eta,y(1)+(y(2)-y(1))*ksi+(y(3)-y(1))*eta)
- endfunction
- for i=1:n
- calka=calka+(F(ksi(i),eta(i))*wi(i))
- end
- disp(0.5*calka)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement