Plotting a polynomial function with roots

2 views (last 30 days)
Christina Cruz
Christina Cruz on 23 Oct 2016
Commented: Robert on 23 Oct 2016
Hi there! I have barely have an idea of what to do with MatLab as of now and my professor pretty much leaves us to do the problems on our own without even teaching the basics first.
He gave us this problem: plot the function showing its roots. Label the roots r1, r2, etc.
f(x) = (x^3) - 10/((2-x)^2) + 25
i got one root through the fixed point iteration method which is roughly 1.3997 but i don't know how to plot this. Any help would be highly appreciated. Thanks in advance!
  1 Comment
Robert
Robert on 23 Oct 2016
Edited: Robert on 23 Oct 2016
Please don't forget to accept the answer Thanks!
syms x
f = (x^3) - 10/((2-x)^2) + 25 % Original function
%same function but rearranged
%Matlab needs to rearrange the function to be in the form of a polynomial
f_rearranged = x^5 -4*x^4 + 4*x^3 +25*x^2 -100*x+90
% Collect the coefficients in decending order
[My_coeffs,~] = coeffs(f_rearranged,x)
roots(My_coeffs) %Get the roots

Sign in to comment.

Answers (1)

Andrei Bobrov
Andrei Bobrov on 23 Oct 2016
syms x
f = x^3 - 10/(2-x)^2 + 25
[n,~] = numden(f);
[c,~] = coeffs(n);
your_roots = roots(double(c));
your_roots = your_roots(imag(your_roots)==0)
  1 Comment
Robert
Robert on 23 Oct 2016
Why are you removing imaginary roots? The answer is incomplete

Sign in to comment.

Categories

Find more on Spline Postprocessing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!