Trying to retrieve and display the initial value of an input
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ibrahim Ali
am 26 Sep. 2021
Kommentiert: Ibrahim Ali
am 27 Sep. 2021
From disp(q), I'm trying to show the interval chosen at the beginning from x0 to x1, the loop makes it so that x0 and x1 get changed, therefore I'm trying to specify a = the initial value of x0, and b = the initial value of x1, but Matlab gives an error:
Error in sekantH (line 3)
x0 = a;
Does anyone have a solution to this problem I'm having?
-------------------------------
function f = sekantH(f,x0,x1)
x0 = a;
x1 = b;
format long;
tol = 10^-10;
count = 0;
for i = 1:1000
x = x1-f(x1) * (x1-x0)/(f(x1)-f(x0));
count = count+1;
if abs(x1-x)<tol
break
end
x0 = x1;
x1 = x;
f = x;
count;
q = ['Number of iterations on the interval', ' [', num2str(a), ',' ,num2str(b), '] is = ', num2str(count), '. And the root is: '];
disp(q)
end
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!