Typing a script that uses incremental search to identify intervals.

5 views (last 30 days)
Typing a script that uses incremental search to identify intervals where the roots of the equation -260x^2 + 44x + 156 Are.
Take averages of the interval bounds as an approximation of the roots and make sure to use a step size that gives an absolute true error of the function value less than 0.01.
Your script should display the function value at the approximated roots.
So I try out these 2 code but some of them doesn’t work properly because it is larger than 0.01 or the code is quite long.
x1 = -1;
x2 = x1 +0.001;
while true
y1= (-260.*x1.^2)+(44.*x1)+156;
y2= (-260.*x2.^2)+(44.*x2)+156;
if (y1>0 && y2<0) || (y1<0 && y2>0)
break
end
x1 = x1 + 0.001;
x2 = x2 + 0.001;
end
root1 = (x1+x2)./2;
x3 = x1 + 0.001;
x4 = x2 + 0.001;
while true
y3= (-260.*x3.^2)+(44.*x3)+156;
y4= (-260.*x4.^2)+(44.*x4)+156;
if (y3>0 && y4<0 ) || (y3<0 && y4>0)
break
end
x3 = x3 + 0.001;
x4 = x4 + 0.001;
end
root2 = (x3+x4)./2;
root1
root2
This is the another short one
f = @(x) ((-260.*x.^2)+(44.*x)+156);
x = [0:0.01:1];
%h = 0.01
disp(f(x))
  2 Comments
John wick
John wick on 4 Sep 2019
The first one give the result but it's quite long. Feel like it could be simplify. The second one is short and simple but it display more than it needed

Sign in to comment.

Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!