Question

In: Electrical Engineering

Implement in MATLAB the Newton-Raphson method to find the roots of the following functions. (a) f(x)...

Implement in MATLAB the Newton-Raphson method to find the roots of the following functions.

(a) f(x) = x 3 + 3x 2 – 5x + 2

(b) f(x) = x2 – exp(0.5x)

Define these functions and their derivatives using the @ symbol. For example, the function of part (a) should be f=@(x)x^3 + 3*x.^2 - 5*x + 2, and its derivative should be f_prime=@(x)3*x.^2 + 6*x - 5.

For each function, use three initial values for x (choose between -10 and 10), so that you can find more than a single root, if possible. Each time you run the algorithm, keep the values of x for each iteration, and plot them with respect to the iteration number.

Plot each function for x between -10 and 10 (e.g., x=-10:0.1:10;) to confirm visually that the roots that you found are where they are supposed to be. You may zoom in as you see fit to get a clearer picture about where the roots are.

Solutions

Expert Solution

function root=newton(x0)
count=0;
error=1;
tol=10^(-7);
max=50;
f=@(x)x^3 + 3*x.^2 - 5*x + 2;
f_prime=@(x)3*x.^2 + 6*x - 5;

while(error>tol & count<max)
fx=f(x0);
dfx=f_prime(x0);
x1=x0-fx/dfx;
if dfx==0
disp('derivative is zero');
return
end
count=count+1;
error=abs(x1-x0);
x0=x1;
iteration=[x1 error count];
x0=x1;
end
ezplot(f,[-10 10])
grid on
hold on
plot(x1,f(x1),'ro')

root=x1;
end

Command Wndow

There should be three roots but through newton raphson coding only one root can be found out. I have actually removed the if condition so that I get atleast two roots which you can see on the plot.

-----------------------------------------------------------------------------------------------------------------------------

function root=newton(x0)
count=0;
error=1;
tol=10^(-7);
max=50;
f=@(x)x^2 - exp(0.5*x);
f_prime=@(x)2*x - 0.5*exp(0.5*x);

while(error>tol & count<max)
fx=f(x0);
dfx=f_prime(x0);
x1=x0-fx/dfx;
if dfx==0
disp('derivative is zero');
return
end
count=count+1;
error=abs(x1-x0);
x0=x1;
iteration=[x1 error count];
x0=x1;
end
ezplot(f,[-10 10])
grid on
hold on
plot(x1,f(x1),'ro')

root=x1;
end

Command Window

Here I have managed to get three roots.


Related Solutions

Use Bisection and Newton Raphson methods to find roof for the following equation manually. F(x)=x^2 –...
Use Bisection and Newton Raphson methods to find roof for the following equation manually. F(x)=x^2 – 5 = 0 ε = 0.01
Find a root of an equation f(x)=5x3-3x2+8 initial solution x0=-0.81, using Newton Raphson method
Find a root of an equation f(x)=5x3-3x2+8 initial solution x0=-0.81, using Newton Raphson method
Determine the roots of the following simultaneous nonlinear equations using multiple-equation Newton Raphson method. Carry out...
Determine the roots of the following simultaneous nonlinear equations using multiple-equation Newton Raphson method. Carry out two iterations with initial guesses of x1(0) =0.6 and x2(0) =1.2. Calculate the approximate relative error εa in each iteration by using maximum magnitude norm (║x║∞). x1 + 1 - x22 = 0 x12 + x22 – 5 = 0
Using Newton-Raphson method, find the complex root of the function f(z) = z 2 + z...
Using Newton-Raphson method, find the complex root of the function f(z) = z 2 + z + 1 with with an accuracy of 10–6. Let z0 = 1 − i. write program c++ or matlab
Determine the root of f (x) = 10.5X² - 1.5X - 5 by using Newton Raphson...
Determine the root of f (x) = 10.5X² - 1.5X - 5 by using Newton Raphson method with x0 = 0 and perform the iterations until ɛa < 1.00%. Compute ɛt for each approximation if given the true root is x = 0.7652.
Using Matlab, create a code that determines the highest real root of f(x)=x3-6x2+11x-6.1 using the Newton-Raphson...
Using Matlab, create a code that determines the highest real root of f(x)=x3-6x2+11x-6.1 using the Newton-Raphson method with x0=3.5 for three iterations. Verify that the process is quadratically convergent. I found the code to get the highest real root (root for three iterations = 3.0473), however, I do not know how to verify that it is quadratically convergent.
use muller's method to find the roots of the equation f(x) = sin x - x/2...
use muller's method to find the roots of the equation f(x) = sin x - x/2 =0 near x=2
On Matlab use BFGS Method to find the minimum of the following function: f(x) = x13...
On Matlab use BFGS Method to find the minimum of the following function: f(x) = x13 - 2x2x12 + x12 - x1using initial point (x0, y0) = (1, 2)T to start, and stop when f changes less than 0.0001
In matlab ask the user to select whether to repeat the Newton-Raphson calculation or end the...
In matlab ask the user to select whether to repeat the Newton-Raphson calculation or end the program. If the user exits out of the menu, repeat the request until the user makes a selection. If the program is repeated, store the new final value of the root and new number of iterations in the same variables without overwriting the previous results. Once the user chooses to end the program, save the variables containing the root values and numbers of iterations...
GIVEN: COS(x) +3xe^-x=0 USING NEWTON RAPHSON METHOD Find: 1.) The POSITIVE ROOT USING X0=2 2.) THE...
GIVEN: COS(x) +3xe^-x=0 USING NEWTON RAPHSON METHOD Find: 1.) The POSITIVE ROOT USING X0=2 2.) THE NEGATIVE ROOT USING X0=-0.5 *STOPPING CRITERION ≤ 0.01% use radian mode in calcu and i dont want a program answers pls i need the manual method.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT