Transcript
Assignment #1 Set2, Question 2: f=inline ('3*x^2-1-exp(-0.5*x)'); a=fzero(f,[-2 0]) z=fzero(f,[0 5]) COMMAND WINDOW: >> Assign1_set2_q2 a = -0.9294 z = 0.7500 Set2, Question 3: p=[1 -26 4] root=roots(p) COMMAND WINDOW: >> Assign1_set2_q3 p = 1 -26 4 root = 25.8452 0.1548 Set2, Question 4: function F = nle(x) F=[x(1)^3+2*x(2)^2-10;x(1)*x(2)-2]; %Equations to be solved %For command window %x0=[5 -1] ; %options=optimoptions('fsolve','Display','iter); %x=fsolve('nle',x0,options); x0=[5;-1] ; COMMAND WINDOW: >> x0=[5;-1]; options=optimoptions('fsolve','Display','iter'); [x]=fsolve(@nle,x0,options) Norm of First-order Trust-region Iteration Func-count f(x) step optimality radius 0 3 13738 8.78e+03 1 1 6 3153.26 1 2.69e+03 1 2 9 367.324 1 508 1 3 12 36.7625 1.46808 112 2.5 4 15 1.44632 0.510485 16.1 2.5 5 18 0.0118827 0.15926 1.3 2.5 6 21 1.83016e-06 0.0181682 0.016 2.5 7 24 5.04862e-14 0.000235669 2.65e-06 2.5 8 27 1.5506e-28 3.93584e-08 1.49e-13 2.5 Equation solved. fsolve completed because the vector of function values is near zero as measured by the default value of the function tolerance, and the problem appears regular as measured by the gradient. <stopping criteria details> x = 2.0000 1.0000 Set 3, Question 1 x=[-pi:pi/100:pi]; y1=(3/5)*cos(x/2); y2=3*sin(x/3); plot(x,y1,'-k',x,y2,'--b') xlabel('X') ylabel('Y') title('Plot of y1=(3/5)*cos(x/2) and y2=3sin(x/3)') grid on axis([-3 3 -2 2]) legend('y1','y2') Set 3, Question 2 x=[-2:0.01:2]; y=3*x.^4-2*x.^2-2 ; y1=0; plot(x,y,'-k') xlabel('X') ylabel('Y') title('Set3 Question2') axis([-2 2 -4 16]) hold on plot(x,y1,'r') hold off p=[3 0 -2 0 -2] r=roots(p) COMMAND WINDOW >> f3 p = 3 0 -2 0 -2 r = -1.1024 + 0.0000i 1.1024 + 0.0000i 0.0000 + 0.7407i 0.0000 - 0.7407i