1

**Off Topic / Re: Need help in MATLAB**

« **on:**September 19, 2019, 04:20:27 PM »

a) is telling you to do 3 iterationsYeah I was confused by what tolerance meant as well, I assume that tolerance is the number of digits the midpoint has. Like in this script here(This is from a different problem):

b) is telling you to figure out how many iterations it takes to reach a value with the tolerance of 10^-5, given the starting bracket.

i presume tolerance here means the distance of the current value from the minima.

Code: [Select]

`clear all;`

xL = 0;

xR = 1.5;

f = @(x) (sin(x) - cos(3*x));

alpha = 10^-6;

maxloops = 25;

for i = 1:maxloops

xM = (xL+xR)/2; %xM = x*

if f(xM)*f(xR)<0

xL=xM;

elseif f(xM)*f(xL)<0

xR=xM;

end

if abs(f(xM))<alpha

break

end

end

xM;

a = xM;

disp("The value of x* is");

disp(a);

disp("The value of f(x*) is");

disp(f(xM));

disp("The number of iterations attempted was");

disp(maxloops);

disp("The maximum number of iterations performed was")

disp(i);

disp("A grpah of the funtion with xL=0 to xR=1.5 is now being

displayed");

Problem3Plot;

I set it so that the script stops once it reaches a specific alpha value, the tolerance I think is the same thing as whats happening with alpha. At least I hope so because I already submitted the assignment.