| 1 | initial version |
Your question actually appears to be two homework questions.
1) Find the x-intercept for the given polynomial.
Your code has some extraneous lines in it. So, I'll shorten it.
f(x)=x^3 + 4*x - 7
p1= plot(f(x), (x,-15,15), ymin=-15, ymax=15)
show(p1)
This plot shows just one real root.
ans=solve(f(x)==0,x)
print ans
Solve gives two nonreal roots and one real root. This is consistent with the plot, and you can get the real root using:
ans[2].rhs().n()
Another option is to use find_root to find the root numerically:
find_root(f(x),0,3)
Either way, you get the answer you expected: 1.25538315684475
Substituting this into f should give you 0, and what you saw was that you got 10^(-15) which is VERY close to zero. This often happens when using numerical approximations.
2) given f(x) = x^3 + 4*x - 2, one needs to evaluate f^-1(-5)
You need to use solve find x-values for which f(x)=-5.
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.