Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Rewrite this code to be simpler in MATLABTask 4 . Fix what is wrong in the code. MATLAB. Functions: f ( x ) = 2
Rewrite this code to be simpler in MATLABTask Fix what is wrong in the code. MATLAB. Functions:
fxxxx Interval:
Tolerance: Maximum number of iterations:
sims x
fxfunction;
xp beginning of the interval;
xk end of interval;
tol ;
maxiter ;
iter ;
conP ;
conK ;
defining the function for convergence
gx fxx;
gx x fxdifffx;
print
string xp::xk;
fplotfxxp xkb
hold on
lin string;
plotstringlin, r
hold on
fplotgxxp xkg
hold on
plotstring"Color","c
axisxp xk
hold off
xlabelx
ylabelfx
algorithm
fprintfiter xL fxL xD fxD
fprintf
while iter
if absfxp tol && konP && iter
conP ;
interP iter;
elseif conP
xpvpagxp;
xp xp; setting a new value to check from the beginning of the interval
conP ;
end
if absfxk tol & konK & iter
conK ;
interK iter;
elseif conK
xkvpagxk;
xk xk; setting a new value to check from the beginning of the interval
conK ;
end
if konP & konK & iter
fprintfthe function converges on the L side after d iterations',interP
fprintfpoint obtained : fxp
fprintffunction value at the obtained point : ffxp
break
end
if konK & konP & iter
fprintffunction converges on D side after d iterations',interK
fprintfpoint obtained : fxk
fprintffunction value at the obtained point : ffxk
break
end
if konK & konP
fprintffunction converges on both sides'
fprintffrom L side after d iterations from D side after d iterations', interP, interK
fprintfobtained points with L : f and with D: fxp xk
fprintffunction value in obtained points L : f D: f fxp fxk
break
end
fprintfd f f f f
iter,xpfxpxkfxk
iter iter ; iteration increment
end
if iter
fprintfconvergence not reached in iterations
fprintflast calculated x are f
and f
xp xk
fprintfvalue of function f at these points is: f
and f
fxp fxk
end
if the condition is not reached in iterations, the program prints the required data
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started