Author Topic: Need help in MATLAB  (Read 526 times)

Ok so I have to do this problem for a class



I am confused because aren't you supposed to know the tolerance before you are able to do the iterations?  If you are able to calculate tolerance how does one do so?

a) is telling you to do 3 iterations
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.

a) is telling you to do 3 iterations
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.
Yeah 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):
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.