Solving a cubic equation

10 ビュー (過去 30 日間)
Inbanathan Govender
Inbanathan Govender 2013 年 12 月 18 日
回答済み: John D'Errico 2013 年 12 月 18 日
Hi,
I have the following equation to solve
Z^3 - (1-B)Z^2 + Z(A-3B-2B^2) - (AB-B^2-B^3)
A and B are vectors. Can the solve function be used to output the roots in an nx3 matrix?

回答 (2 件)

Matt J
Matt J 2013 年 12 月 18 日
編集済み: Matt J 2013 年 12 月 18 日
I would just use ROOTS in a loop.

John D'Errico
John D'Errico 2013 年 12 月 18 日
As Matt says, roots in a loop will work. Often the simplest is best, as why expend programming time on something so simple.
If you really want it to be vectorized, you COULD convert the array into a cell array. The use cellfun, with @roots to solve all the problems at once.
If you REALLY want it vectorized and fast as blazes, then since this is a cubic polynomial, use the classic solution for the roots of a cubic given the coefficients. That formula can be used in a vectorized form. Trivial really. This is in fact what we did when we had to solve that same problem, and we wanted pure speed.

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by