Programming in MatLab (OCTAVE ONLINE) and taking the following mathematical expr
ID: 2072445 • Letter: P
Question
Programming in MatLab (OCTAVE ONLINE) and taking the following mathematical expression:x^5 + x + 1=0
***Find the roots.***
Considerations:
• use: clear all, clc, disp, fprint, input, if-else, for, while, subprograms, vectors, matrix...
• do not use: roots, fzero, poly, polyval, residue, floor... Programming in MatLab (OCTAVE ONLINE) and taking the following mathematical expression:
x^5 + x + 1=0
***Find the roots.***
Considerations:
• use: clear all, clc, disp, fprint, input, if-else, for, while, subprograms, vectors, matrix...
• do not use: roots, fzero, poly, polyval, residue, floor... Programming in MatLab (OCTAVE ONLINE) and taking the following mathematical expression:
x^5 + x + 1=0
***Find the roots.***
Considerations:
• use: clear all, clc, disp, fprint, input, if-else, for, while, subprograms, vectors, matrix...
• do not use: roots, fzero, poly, polyval, residue, floor...
Explanation / Answer
MATLAB code:
clc
clear all
expre=input('Enter vector form of the mathmatical expression : ');
c = expre(:).';
n = size(expre,2);
x = find(expre);
nnz = length(x);
c = c(x(1):x(nnz));
r = zeros(n-x(nnz),1,class(c));
d = c(2:end)./c(1);
while any(isinf(d))
c = c(2:end);
d = c(2:end)./c(1);
end
n = length(c);
if n > 1
a = diag(ones(1,n-2,class(c)),-1);
a(1,:) = -d;
r = [r;eig(a)]
end
example:
Enter vector form of the mathmatical expression : [1 0 0 0 1 1]
r =
0.8774 + 0.7449i
0.8774 - 0.7449i
-0.5000 + 0.8660i
-0.5000 - 0.8660i
-0.7549
>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.