Typing a script that uses incremental search to identify intervals.
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!