Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %%2
- %% 1. uzdevums
- clear all, close all, clc
- format longG
- x=-4:0.0001:3;
- f=@(x)3*sin(0.8*x)-x.^3+7*x-6;
- plot(x,f(x),'r','LineWidth',3)
- grid
- %pirma_sakne=fzero(f,-3.0895)
- %otra_sakne=fzero(f,0.67)
- %tresa_sakne=fzero(f,2.38)
- XN=[-3.0895 0.67 2.38]; % saknu tuvinajumi
- iter=6;
- syms x
- n=length(XN);
- fpr=diff(f(x),x);
- for j=1:n
- xn=XN(j);
- for i=1:iter
- xn=xn-f(xn)/subs(fpr,x,xn);
- M(i,1)=double(xn);
- M(i,2)=double(f(xn));
- end
- saktuv=XN(j), M
- end
- %% 2. uzdevums
- clear all, close all, clc
- zim1 = ezplot('sin(x2+1)-x1-1.2',[-0.22, -0.2, 0.5, 0.55])
- hold on
- zim2 = ezplot('2*x2+cos(x1)-2',[-0.22, -0.2, 0.5, 0.55])
- set(zim1,'Color','r','LineWidth',3)
- set(zim2,'Color','b','LineWidth',3)
- grid
- %no grafika x1= -0.203 un x2= 0.51
- syms x1 x2
- epsi=1; xtuv=[-0.203 0.51]; xpr=[x1 x2]; % saliek no grafika nolasitos p-tus
- F=[sin(x2+1)-x1-1.2,2*x2+cos(x1)-2]; % ievada dotas funkcijas
- Apr=[diff(F(1),xpr(1)) diff(F(1),xpr(2))
- diff(F(2),xpr(1)) diff(F(2),xpr(2))];
- k=1;
- while epsi > 10^(-3)
- for i=1:2
- B(i,1)=-subs(F(i),xpr,xtuv);
- for j=1:2
- A(i,j)=subs(Apr(i,j),xpr,xtuv);
- end
- end
- xdelta=double(A\B); xtuv=xtuv+xdelta';
- c=double(subs(F,xpr,xtuv)); epsi=norm(c);
- PR(k,1)=xtuv(1);
- PR(k,2)=xtuv(2);
- PR(k,3)=epsi;
- k=k+1;
- end
- format longG
- %iegust atrisinajumu
- PR %x1 x2 epsi
- %% 3. uzdevums
- clear all, clc, close all
- xint = [0,4]; % interv?ls
- % s?kuma nosac?jumi
- %x(0) = 3;
- %y(0) = 2;
- y0 = [3;2];
- sol = ode45(@func_uzd3,xint,y0);
- xx = [0:0.1:4]; % x v?rt?bu vektors
- y = deval(sol,xx); % y v?rt?bu vektors
- plot(xx,y(1,:),'r',xx,y(2,:),'g','LineWidth',3)
- grid
- legend('x(t)','y(t)')
- xlabel('t')
- ylabel('y')
- %t=2.2;
- %3.1 x(t) = -2.3
- %3.2 y(t) = 0.2
- %3.3 3?
- %3.4 2.7?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement