display function does not show the exact value

I am new to MATLAB. I wrote code like this;
syms n
f(n) = 40*n.^1.5-875*n+35000;
fdiff(n) = diff(f(n));
x0 = 100;
xprev = 0;
while (abs(x0 - xprev)/x0)*100 >= 1
xprev = x0;
x0 = x0 - f(x0)/fdiff(x0);
end
display(x0);
When I tried to display the value of x0, it shows;
600/11 - (40*(600/11 - ((24000*11^(1/2)*600^(1/2))/121 - 140000/11)/((60*11^(1/2)*600^(1/2))/11 - 875))^(3/2) + (875*((24000*11^(1/2)*600^(1/2))/121 - 140000/11))/((60*11^(1/2)*600^(1/2))/11 - 875) - 140000/11)/(60*(600/11 - ((24000*11^(1/2)*600^(1/2))/121 - 140000/11)/((60*11^(1/2)*600^(1/2))/11 - 875))^(1/2) - 875) - ((24000*11^(1/2)*600^(1/2))/121 - 140000/11)/((60*11^(1/2)*600^(1/2))/11 - 875)
Instead of just;
62.6913
How can I make it to display only the final value?

2 件のコメント

Andreas Sorgatz
Andreas Sorgatz 2016 年 3 月 21 日
The answer is a representation of the "exact" value. However, you can get an approximation of this exact result using vpa(...) if you need high precision or using double(...) if hardware precision is fine.
Álvaro Sacristán Gonzalez
Álvaro Sacristán Gonzalez 2021 年 9 月 26 日
I fixed it with disp(vpa(x)), which gives you 32 digits of precision. Newton-Raphson function analysis here 2 :D

サインインしてコメントする。

 採用された回答

その他の回答 (1 件)

John BG
John BG 2016 年 2 月 27 日

1 投票

Mustafa
If you are really after a numeric result, why don't start with numeric values?
x_range=10
x_step=.1
x=[0:x_step:x_range]
f=@(x) 40*x.^1.5-875*x+35000
y=f(x)
ydiff = diff(y)
x0 = 100
xprev = 0
while (abs(x0 - xprev)/x0)*100 >= 1
xprev = x0
x0 = x0 - f(x0)/ydiff(x0)
end
x0 =
-82.29
Play with x_range and x_step to center the curve wherever you need.
If you find this answer of any help solving this question, please click on the thumbs-up vote link,
thanks in advance
John

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by