bisection method error symbolic
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Faisal Al-Wazir
am 7 Okt. 2022
Kommentiert: Faisal Al-Wazir
am 7 Okt. 2022
hi i'm trying to write a code to solve this question:
the code below need some adjustment to make it work
clear
clc
syms y
q=20;
g=9.8;
b=3+y;
ac=3*y+((y^2)/2);
f=@(y) 1-((q^2)/(g*ac^3)*b);
x1=0.5
xu=2
ezplot(f(y))
grid on
hold on
for i=1:100
xr(i)=(x1+xu)/2
if ((f(x1)*f(xr(i)))<0)
xu=xr(i)
elseif ((f(x1)*f(xr(i))>0))
x1=xr(i)
elseif ((f(x1)*f(xr(i))==0))
break
end
if ((i>1)&&(abs((xr(i)-xr(i-1)))/xr(i-1))*100<0.01)
break
end
plot(xr(i),f(xr(i)),'xr')
end
xr(10)
0 Kommentare
Akzeptierte Antwort
Torsten
am 7 Okt. 2022
syms y
q=20;
g=9.8;
b=3+y;
ac=3*y+y^2/2;
f= 1-q^2/(g*ac^3)*b;
x1=0.5;
xu=2.5;
hold on
fplot(f,[0.5 2.5])
grid on
f = matlabFunction(f);
for i=1:100
xr(i)=(x1+xu)/2;
if ((f(x1)*f(xr(i)))<0)
xu=xr(i);
elseif ((f(x1)*f(xr(i))>0))
x1=xr(i);
elseif ((f(x1)*f(xr(i))==0))
break
end
if ((i>1)&&(abs((xr(i)-xr(i-1)))/xr(i-1))*100<0.01);
break
end
end
plot(xr,f(xr),'xr')
hold off
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Calculus 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!