How do you separate the roots of a function?

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

Ahsan
Ahsan 2014년 10월 15일
Maybe I should just use the quadratic formula? However, I am wondering if there is any other way.

댓글을 달려면 로그인하십시오.

 채택된 답변

Michael Haderlein
Michael Haderlein 2014년 10월 15일

1 개 추천

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.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 10월 15일

2 개 추천

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

Manoj
Manoj 2018년 4월 22일
% 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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2014년 10월 15일

댓글:

2018년 4월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by