Clear Filters
Clear Filters

How do you separate the roots of a function?

2 views (last 30 days)
For example, I wrote the following:
% a b c and d are input from the user
qx = [a b c d]; %a*x^3 + b*x^2 + c*x + d
derivative_qx = [3*a 2*b c]; %3*a*x^2 + 2*b*x + c
r = roots(derivative_qx);
disp(r);
If there are two roots how do I obtain the value of each separately so they are assigned to two different variables, such as r1 and r2. I was only able to find the roots function searching around, which displays both together.
Thanks
  1 Comment
Ahsan
Ahsan on 15 Oct 2014
Maybe I should just use the quadratic formula? However, I am wondering if there is any other way.

Sign in to comment.

Accepted Answer

Michael Haderlein
Michael Haderlein on 15 Oct 2014
Actually, this is exactly how you should do it. Don't assign it to variables like r1, r2. It will be much more difficult to work with these variables than to work with the array r containing the same values.
If you really want to go with r1...r2: As the order of your polynomial is hard-coded (2nd order), you can also hard-code this part such as
r1=r(1);
r2=r(2);
Anyway, I wouldn't recommend it.

More Answers (1)

Andrei Bobrov
Andrei Bobrov on 15 Oct 2014
qx = input('input as double array [1 x 4] = ');
dq = polyder(qx);
r = roots(dq);
use r(1) as r1 and r(2) as r2
  1 Comment
Manoj
Manoj on 22 Apr 2018
% q1 %% Section 1a % Define crank length a=1;b=2;c=4;d=5;theta2=30; % Define input parameters and anonymous functions x1=120;xu=165;xi=120;xi_1=110;delta=0.01;precision=0.0001; f= % Student can choose one of these methods, all works % nr = newraph(f, df, xi, precision); % sc = secant(f, xi, xi_1, precision); % ms = modisecant(f, xi, pert, precision); % fzv = fzero(f, xi); % fzb = fzero(f, [xl, xu]);
%
%% Section 1b
% Define crank length
% Define input parameters for function
% Solve for root, for all ang2
% Plot the relation between the input angles and the output angles
%% Section 1C
%% Section 1D
% Write the result into text file

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!