Question

Consider the function f(x) = x3 – 2x2 + x Write the MATLAB code in the format of script file using Regula Falsi Method wi

0 0
Add a comment Improve this question Transcribed image text
Answer #1

clc;

clear all ;

%regula falsi method

f = @(x) (x^3-2*x^2+1.5*x); % the given function

n=0.1;

while (f(n)*f(-n) > 0) % here we are finding the the interval [a,b] where the f(a)f(b)<0

n=n+0.1;

end

a=-n; % f has a root in [a,b]

b=n;

%%%% here we are calculating the 1st approximation of the root c(1)

c(1)=(a*f(b)-b*f(a))./(f(b)-f(a)); % here we are using the Regula-Falsi method, c=(a*f(b)-b*f(a))/(f(b)-f(a))

if f(a)*f(c(1))<0 % if f (a) * f (c) < 0 then b = c else a = c

b=c(1);

else

a=c(1);

end

error=10;

i=2;

while (error>0.000001)

c(i)=(a*f(b)-b*f(a))./(f(b)-f(a)); % here we are using the Regula-Falsi method, c=(a*f(b)-b*f(a))/(f(b)-f(a))

if f(a)*f(c(i))<0 % if f (a) * f (c) < 0 then b = c else a = c

b=c(i);

else

a=c(i);

end

error=abs(abs(c(i)-c(i-1))./c(i)); % calculating relative error

i=i+1;

end

fprintf('The root with the relative error of 0.000001 is %f',c(end))

regula_falsi.mx + clc; clear all ; %regula falsi method f = @(x) (x^3-2*x^2+1.5*x); % the given function n=0.1; while (f(n)*fCOMMAND WINDOW The root with the relative error of 0.000001 is 0.000000 >>

Add a comment
Know the answer?
Add Answer to:
Consider the function f(x) = x3 – 2x2 + x Write the MATLAB code in the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given the equations write a Matlab Function File (code) for 10x1 + 2x2 - x3 =...

    Given the equations write a Matlab Function File (code) for 10x1 + 2x2 - x3 = 27 -3x1 -5x2 +2x3 = -61.5 x1 +x2 +6x3 = -21.5 (A) Compute the determinant (B) Use Cramer's rule to solve for the x's (C) Solve by naive Gauss elimination. Show all steps of the computation.

  • NOTE: WRITE MATLAB CODE then the results for each QUESTIONS: Q1: For the system of the...

    NOTE: WRITE MATLAB CODE then the results for each QUESTIONS: Q1: For the system of the equations [2x; + 3xy + x3 = 9 x2 + 2x2 + 3x3 = 0 3x; +x2+2x3 = 8) compute the unknowns Xı, X2, and X3 using the inverse matris method. Q2: Simplify the complex number z and express it both in rectangular and polar form. (3+ j4)(5 + j2)(2 260°) (3+j6)(1+12) NOTE: WRITE MATLAB CODE then the results for each QUESTIONS: Q3: Suppose...

  • In MATLAB please Consider the nonlinear function: y = f(x) = x3 cos x a. Plot...

    In MATLAB please Consider the nonlinear function: y = f(x) = x3 cos x a. Plot y as a function of x as x is varied between -67 and 67. In this plot mark all the locations of x where y = 0. Make sure to get all the roots in this range. You may need to zoom in to some areas of the plot. These locations are some of the roots of the above equation. b. Use the fzero...

  • please solve then upload matlab code Thanks 1. The function f(z, y) (a-x)2 + b(y-12)2 is...

    please solve then upload matlab code Thanks 1. The function f(z, y) (a-x)2 + b(y-12)2 is called Rosenbrock's banana function. It is often used as a benchmarking test for optimization algorithms becatse it is easy to find the minimum by hand but often very difficult to find numerically. Throughout the problem, we will use the values a = 2 and b 10. You can plot this function using the following code: x3:0.1:3; y = -10:0.2:10; Cx,Ymeshgrid(x,y); Z(2-X).2 10* (Y-X. 2)....

  • The matlab code for the following problem is appreciated!! QUESTION 3 Write a function fnfr_plot that...

    The matlab code for the following problem is appreciated!! QUESTION 3 Write a function fnfr_plot that will receive two function handles from elementary math functions which accept a vector to first sort in ascending order then calculate. The script will display the results in two separate Figure Windows with the function names in the title. Submit: fnfr_plot.m Browse My Computer Attach File QUESTION 4 Generate 1x100 random vector, x in the range of 0<x<100 by using rand. Input 2 elementary...

  • 1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...

    1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...

  • Lab Exercises This lab assignment includes three items. You will write a file containing psuedocode, one...

    Lab Exercises This lab assignment includes three items. You will write a file containing psuedocode, one Matlab function and one Matlab script. The script ca the function and your psuedocode must be robust enough to be a clear basis for the function and script files. The function you will write must implement the method of Naïve Gauss Elimination. Here is the official assignment: 1. Psuedocode Write psuedocode for a function implementing Naive Gauss Elimination. Save this pseudocode to a file...

  • DO NOT GIVE ME A STEP BY STEP SOLUTION ON PAPER. JUST GIVE ME THE MATLAB FUNCTION FILE (code) TO...

    DO NOT GIVE ME A STEP BY STEP SOLUTION ON PAPER. JUST GIVE ME THE MATLAB FUNCTION FILE (code) TO BE USED IN MATLAB. ONLY (a) use the Gauss-Seidel method to solve the following system until the percent relative error falls below s a. 5%. 10x1 + 2x2-x,-27 3x1 -6x2 + 2x3 61.5 25x321.5 b. (b) write an M-file to implement the Gauss-Seidel method using the above system as a test case (a) use the Gauss-Seidel method to solve the...

  • USE MATLAB TO WRITE A CODE FOR THIS 2. Writ example 4.5% as 4.5) and the...

    USE MATLAB TO WRITE A CODE FOR THIS 2. Writ example 4.5% as 4.5) and the number of monthly payments (use the Calculate the down payment using the percent down payment e e a program that gets a cost, percent down payment, annual interest rate as a percent (for ntered, the loan amount (cost - own payment) and monthly interest rate as a decimal number -not a percent. Call your payment function to calculate the payment on the loan amount....

  • Please show the code necessary, and explanations on MATLAB. Plotting 11) Plot the function y =...

    Please show the code necessary, and explanations on MATLAB. Plotting 11) Plot the function y = sin(x) from x = 0 to 21. 12) Plot the functions y = x2 z = x2 + 2x + 1 from x = 0 to 2 on the same graph. Scripts: Input and Output 13) Write a script (M-file) to read in a message at the command line using the MATLAB input function and then display the message to the Command Window using...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT