Info

This question is closed. Reopen it to edit or answer.

Which routine to be used for numerically solving a three-order equation represented in an array?

2 views (last 30 days)
Hi all,
I'm sorry if the title is not clear enough. What I want to solve is an equation like
y^3 + a y^2 + b y + c = 0,
where y=y(x) and c is an array (or function) of x (I don't have an analytical expression for it) and for a,b they are constants. I know the fsolve routine, but as far as I understand, it can only be used when the explicit expressions of the coefficients are known. How to solve this polynomial? Thanks a lot.
  2 Comments
Walter Roberson
Walter Roberson on 20 Nov 2015
I am not clear what is to be solved for? Is it the case that you know y and you know c, and you want to find a and b?
Mengqi
Mengqi on 12 Dec 2015
Hi, I don't know y, I want to solve y. c is an array actually, so I want to have a numerical result of y. a and b are scalar constants.

Answers (2)

Torsten
Torsten on 20 Nov 2015
For x fixed, you know a, b and c.
So for this fixed x, determine y(x) as
y=roots([1 a b c])
Best wishes
Torsten.
  1 Comment
Mengqi
Mengqi on 12 Dec 2015
Sorry, roots seems not work. c is an array actually, and I want to have a numerical result of y. a and b are scalar constants. If c is a scalar, roots works.

John D'Errico
John D'Errico on 12 Dec 2015
Trivially, one could just use a loop! Loops are not the worst thing in the world.
No matter what you do, the problem is that you will get three solutions for every element of c. So you will need to choose the root of interest.
Or you could use arrayfun.
For example...
a = 2;
b = 5;
c = magic(3);
res = arrayfun(@(ci) roots([1 a b ci]),c,'uniformOutput',false);
res
res =
[3x1 double] [3x1 double] [3x1 double]
[3x1 double] [3x1 double] [3x1 double]
[3x1 double] [3x1 double] [3x1 double]
res{1,1}
ans =
-0.123914110557906 + 2.13316845986304i
-0.123914110557906 - 2.13316845986304i
-1.75217177888419 + 0i

Tags

Community Treasure Hunt

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

Start Hunting!