MATLAB Answers

How to solve a fourth order algebraic equation?

182 views (last 30 days)
R7 DR
R7 DR on 12 Feb 2015
Commented: Star Strider on 13 Feb 2015
How to solve the value of x for the equation 2x^4+x=34.
Can we solve the fourth order algebraic equations using solve command?
Thanks

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 12 Feb 2015
It’s easier than that. Create a vector of its coefficients and use the roots function:
% 2x^4+x=18 -> 2x^4 + x -18 = 0
coefvct = [2 0 0 1 -18]; % Coefficient Vector
x = roots(coefvct) % Solution
produces:
x =
-1.7732e+000 + i
41.6666e-003 + 1.7326e+000i
41.6666e-003 - 1.7326e+000i
1.6899e+000 + i
Two real and two complex roots.

  6 Comments

Show 3 older comments
Star Strider
Star Strider on 12 Feb 2015
My pleasure.
A loop is the easiest way:
C = [20:2:50]; % Define ‘C’
X = nan(4, length(C)); % Preallocate ‘X’
for k1 = 1:length(C)
X(:,k1) = roots([2 0 0 1 -C(k1)]); % Coefficient Matrix
end
The ‘X’ matrix is a (4x16) array with each column the coefficients corresponding the the same element in ‘C’.
Star Strider
Star Strider on 13 Feb 2015
R7 DR’s ‘Answer’ moved here...
Hi Thanks for the reply.
My equation got changed, now I have to solve two varying constants.
For example
ax^4+x=C
C=20,22,24,26,28,30........50
a=1,2,3...16
Could you please tell me, how to find the 'x' value at different 'C' and 'a' values.
I wrote the code like this...
C = [20:2:50]; % Define ‘C’
X = nan(4, length(C));
a=[1:1:length(C)] % Define ‘a’
for i = 1:length(C)
X(:,i) = roots([a(i) 0 0 1 -C(i)]); % Coefficient Matrix
end
Thanks
Star Strider
Star Strider on 13 Feb 2015
My pleasure.
Don’t use ‘i’ and ‘j’ as variables. MATLAB uses them for its imaginary operators, and using them as variables will cause confusion.
This is easy. You need two nested loops and a redefined preallocation:
C = [20:2:50]; % Define ‘C’
a = 1:16; % Define ‘a’
X = nan(4, length(C), length(a)); % Preallocate ‘X’
for k1 = 1:length(C)
for k2 = 1:length(a)
X(:,k1,k2) = roots([a(k2) 0 0 1 -C(k1)]); % Coefficient Matrix
end
end

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by