Given f(x) = 3x + sinx -e^(x) Write a MATLAB user-defined function named Falsepo
ID: 2900471 • Letter: G
Question
Given f(x) = 3x + sinx -e^(x)
Write a MATLAB user-defined function named
Falseposition to solve the equation f(x)=0 with Regula falsi method. Use x(0)= 0 and x(1) =1
as the starting values and a tolerance= 10^(-7)
.
The program should include the following features:
a) The two initial value, the tolerance and the function f are the input of the
Falseposition function and its output is the approximate solution
b) Display the iteration number and the approximate solution iteration by iteration.
c) Use the approximate relative error as the stop criterion and when it
Explanation / Answer
function [ solution ] = Falseposition(input1,input2,tolerance)
%UNTITLED6 Summary of this function goes here
% Detailed explanation goes here
x=linspace(0,1,10);
a=input1;
b=input2;
f = @(y)3*y + sin(y) - exp(-y); %function which root is needed
c=0;
s=0; %iteration number variable
for cnt=2:length(x);
s %iteration number
c=b-(f(b)*(b-a))/(f(b)-f(a)) %approximate solution
if f(a)*f(c)<0
b=c;
else a=c;
if abs(f(c)<tolerance)
cnt=length(x);f(c)
else cnt=2
end
end
s=s+1;
end
solution=c
s
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.