Assignment_2_Solution.pdf - Assignment 2 Solution ECE 2412...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Assignment 2 Solution ECE 2412 - Simulation and Engineering Analysis Haider Mohomad AR Problem 5.5: a) Graphical method %% Problem 5.5 clear;clc;close all % Part (a) x=-1:0.0001:5; f_x = -12 - 21*x + 18*x.^2 - 2.75*x.^3; plot(x,f_x) grid on
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
(b) Bisection Method %% Part (b) Bisection Method clear;clc;close all a=-1; b=0; E_s = 1/100; % The tolerance E_a = 1 + E_s; % initial value of the approximated error must be greater than E_s x_r_old = a; % initial value of x_r_old = a or b count=0; %count will be used to count the number of iterations (optional) f_a = -12 - 21*a + 18*a.^2 - 2.75*a.^3; f_b = -12 - 21*b + 18*b.^2 - 2.75*b.^3; % More efficent way is to replace f_a and f_b by MATALB function that takes % the variable x as input and return f(x) as output. % To check for change in sign in the interval (a,b) if ( f_a*f_b <0) % There is change in sign while (E_a>E_s) x_r = (a + b) / 2; % new estimate of the root f_x_r = -12 - 21*x_r + 18*x_r.^2 - 2.75*x_r.^3; % f(xr) if (f_a*f_x_r < 0) % the root is located between a and x_r b=x_r; f_b=f_x_r; else % the root is located between x_r and b a=x_r; f_a=f_x_r; end %calculating the approximated error E_a = abs((x_r - x_r_old) / x_r) *100; % updating x_r_old x_r_old=x_r; count=count+1; end else % no change in sign between (a,b) error( 'F(a) and f(b) must have different sign' ) end fprintf( ' The estimated root is %0.8f with relative approximated error of %0.8f%% using the bisection method (%0.0f iterations)\n' ,x_r,E_a,count) >> The estimated root is -0.41470337 with relative approximated error of 0.00735889% using the bisection method (15 iterations)
Image of page 2
(b) False Position Method %% (c) False Position clear;clc;close all ; a=-1; b=0; E_s = 1/100; % The tolerance E_a = 1 + E_s; % initial value of the approximated error must be greater than E_s x_r_old = a; % initial value of x_r_old = a or b count=0; %count will be used to count the number of iterations (optional) f_a = -12 - 21*a + 18*a.^2 - 2.75*a.^3; f_b = -12 - 21*b + 18*b.^2 - 2.75*b.^3; % More efficent way is to replace f_a and f_b by MATALB function that takes % the variable x as input and return f(x) as output. % To check for change in sign in the interval (a,b) if ( f_a*f_b <0) % There is change in sign while (E_a>E_s) x_r = b - ( (f_b*(a-b))/(f_a-f_b)); % new estimate of the root f_x_r = -12 - 21*x_r + 18*x_r.^2 - 2.75*x_r.^3; % f(xr) if (f_a*f_x_r < 0) % the root is located between a and x_r b=x_r; f_b=f_x_r; else % the root is located between x_r and b a=x_r; f_a=f_x_r; end E_a = abs((x_r - x_r_old) / x_r) *100; %calculating the approximated error x_r_old=x_r; % updating x_r_old count=count+1; end else % no change in sign between (a,b) error( 'F(a) and f(b) must have different sign' ) end fprintf( ' The estimated root is %0.8f with relative approximated error of %0.8f%% using the false position method (%0.0f iterations)\n' ,x_r,E_a,count) >> The estimated root is -0.41467695 with relative approximated error of 0.00832633% using the false position method (8 iterations)
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Problem 5.17
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern