Typing a script that uses incremental search to identify intervals.

조회 수: 5 (최근 30일)
John wick
John wick 2019년 9월 4일
댓글: John wick 2019년 9월 4일
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