How to input new value as old value using while loop to compute relative error?
Show older comments
I need help on how can I input new value as an old value
Whenever I run the code, the r_e (relative error) equation goes up and gives me a wrong answer
How do I fix this?
f_x= sin (5x) + cos (2x)
for i=1:n
f_l = f_x(x_l);
f_u = f_x(x_u);
p = (x_l+x_u)/2;
f_m = f_x(p);
if (f_l*f_m)<0
x_u=p;
elseif (f_u*f_m)<0
x_l=p;
end
p_old = p;
r_e = abs(p-p_old/(p));
table(i, :)={i-1 p r_e};
fprintf('%d %d %d \n', table{i, :});
end
Accepted Answer
More Answers (0)
Categories
Find more on Linear Algebra in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!