Uploaded by nur laily maulidiyah

KUIS 1 FISKOM CUYY

advertisement

Maria Oktavia Krisanti

1116100057

 Matriks Jacobian function J=Jacobs (func,x,delta)

N=length(x); for i=1:N

xjalan1=x;

xjalan1(i)=x(i)+delta;

xjalan2=x;

xjalan2(i)=x(i)-delta;

J(:,i)=(feval(func,xjalan1)-feval(func,xjalan2))/(2*delta); end end

Penyelesaian:

>> F= @(x)[x(1)^2+x(2)^2+x(3)-14;x(1)^2+2*x(2)^2-9;x(1)-

3*x(2)^2+x(3)]

F =

@(x)[x(1)^2+x(2)^2+x(3)-14;x(1)^2+2*x(2)^2-9;x(1)-

3*x(2)^2+x(3)]

NewtRaphApproxBaru(F,[1;1;1],1e-5,10000) ans =

1.5616

1.8113

8.2808

>> feval(F,ans) ans =

0

0

0

 Invers Matriks Jacobian dengan Gauss-Jordan function p=invJacobs(A)

[a b]=size(A); c=[A eye(a,b)]; if a~=b

Error( 'matriks A bukan matriks persegi' )

pause else for ii=2:a

d=c(ii:a,ii-1)/c(ii-1,ii-1);

c(ii:a,:)=c(ii:a,:)-d*c(ii-1,:); end for jj=a-1:-1:1

u=c(jj:-1:1,jj+1)/c(jj+1,jj+1);

c(jj:-1:1,:)=c(jj:-1:1,:)-u*c(jj+1,:); end for k=1:a

c(k,:)=c(k,:)/c(k,k); end

p=c(:,a+1:2*a); end end

 Aproksimasi Newton-Raphson function m=Newton_Raphson (x,niter)

%call fungsi.m

%call Central.m

%m=zeros(niter,1) m(1)=x; for ii=1:niter-1

m(ii+1)=m(ii)-(fungsi(m(ii))/Central(m(ii),1e-6));

fprintf( 'Iterasion=%iSolusi=%.4f\n' ,ii,m(ii+1)); if abs(m(ii+1)-m(ii))<1e-6;

disp( 'Solusi Konvergence' ) break end if fungsi(m(ii+1))==0

disp ( 'Solusi Eksak telah ditemukan' ) break end end

2. Menghitung ketinggian maksimum, waktu tempuh mencapai tanah, dan jarak maksimum mencapai tanah

 Fungsi Vy(t) function Vy=Vy (V0,theta,g,t)

Vy=V0*sind(theta)-g*t; end

 Fungsi y(t) function y=y2(V0,y0,theta,g,t) y=y0+(V0*sind(theta)*t)-(0.5*g*(t^2)); end

 Fungsi y(x) function y=y1(V0,y0,theta,g,x) y=y0+(x*tand(theta))-((g*x^2)/2*cosd((theta)^2*V0^2)); end

 Fungsi tymax, tmax, dan xmax function GerakParabol(V0,y0),theta,g,delta,Niter) t(1)=0; for i=1:Niter-1

turunan=(Vy(V0,theta,g,(t(i)+delta))-Vy(V0,theta,g,(t(i)delta)))/(2*delta); end thmax=t(akhir) t1(1)=100 for i=1:Niter-1

turunan=(y2(V0,y0,theta,g,(t1(i)+delta))y2(V0,y0,theta,g,(t1(i)-delta)))/(2*delta);

t1(i+1)=t1(i)-(y2(V0,y0,theta,g,t1(i))/turunan); end tmax=t1(akhir) x(1)=100; for i=1:Niter-1

turunan=(y1(V0,y0,theta,g,(x(i)+delta))y1(V0,y0,theta,g,(x(i)-delta)))/(2*delta);

x(i+1)=x(i)-(y1(V0,y0,theta,g,x(i))/turunan); end xmax=x(akhir) end

3. Finite Difference

 Fungsi awal function F=fungsi(x)

F=exp(-3*x)+4*x^2+4; end

 Forward: function Forward(x,deltax) %nama fungsi

%call fungsiUWU.m

Forward =(fungsi(x+deltax)-fungsi(x))/deltax %definisi fungsi end

 Backward: function Backward(x,deltax) %nama fungsi

%call fungsiUWU.m

Backward =(fungsi(x)-fungsi(x-deltax))/deltax %definisi fungsi end

 Central: function Central(x,deltax) %nama fungsi

%call fungsiUWU.m

Central =(fungsi(x+deltax)-fungsi(x-deltax))/(2*deltax)

%definisi fungsi end

Download