Typing a script that uses incremental search to identify intervals.

6 次查看(过去 30 天)
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 个评论
John wick
John wick 2019-9-4
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

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by