How do you separate the roots of a function?
12 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
Michael Haderlein
2014-10-15
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.
0 个评论
更多回答(1 个)
Andrei Bobrov
2014-10-15
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
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!