Path: news.mathworks.com!newsfeed-00.mathworks.com!NNTP.WPI.EDU!elk.ncren.net!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Newsgroups: comp.soft-sys.matlab
Subject: Re: Solve Equation Symbolically
Date: Mon, 12 Nov 2007 20:35:47 +0000 (UTC)
Organization: National Research Council Canada - Conseil national de rechereches Canada
Lines: 80
Message-ID: <fhadf3$o58$1@canopus.cc.umanitoba.ca>
References: <fha99r$osc$1@fred.mathworks.com>
NNTP-Posting-Host: origin.ibd.nrc.ca
X-Trace: canopus.cc.umanitoba.ca 1194899747 24744 192.70.172.160 (12 Nov 2007 20:35:47 GMT)
X-Complaints-To: abuse@cc.umanitoba.ca
NNTP-Posting-Date: Mon, 12 Nov 2007 20:35:47 +0000 (UTC)
Originator: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Xref: news.mathworks.com comp.soft-sys.matlab:437163



In article <fha99r$osc$1@fred.mathworks.com>,
evan klinger <eklinger1-nospam@cox.net> wrote:
>Good afternoon all,
>
>I am trying to solve the equation cv3 below using the solve
>command but for some reason Matlab is not able to solve for
>x. Or it returns strange constants in the result. It also
>sometimes is dropping some of the symbols. I am just trying
>to find out what x equals to. Any help would be greatly
>appreciated.
>cv0, p[n], x, db and cr are all symbols

>cv1 = (cv0 + p1 - (x)*(db-cv0))*(1+cr)
>cv2 = (cv1 + p2 - (x)*(db-cv1))*(1+cr)
>cv3 = (cv2 + p3 - (x)*(db-cv2))*(1+cr)

>I was using solve(cv3, 'x') but this is giving strange
>constants.

It's a cubic in x, so there are three solutions. Two of them
involve imaginary numbers. Because of the numbers of terms involved,
each of the three solutions runs to pages and pages.

If you were using maple directly, you would,

> collect(expand(cv3),x);

(-db+3*cv0*cr^2-3*db*cr+3*cv0*cr+cv0*cr^3-3*db*cr^2-db*cr^3+cv0)*x^3+(-2*db*cr
^3+3*cv0-8*db*cr+3*p1*cr^2+p1-7*db*cr^2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-108*D*A^2-8*B^3+12*3^(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*
D+27*D^2*A^2+4*D*B^3)^(1/2)*A)^(1/3)+1/3*(3*C*A-B^2)/A/(36*C*B*A-108*D*A^2-8*B
^3+12*3^(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*D+27*D^2*A^2+4*D*B^3)^(1/2)*A)^(1/3)-1
/3*B/A-1/2*I*3^(1/2)*(1/6/A*(36*C*B*A-108*D*A^2-8*B^3+12*3^(1/2)*(4*C^3*A-C^2*
B^2-18*C*B*A*D+27*D^2*A^2+4*D*B^3)^(1/2)*A)^(1/3)+2/3*(3*C*A-B^2)/A/(36*C*B*A-\
108*D*A^2-8*B^3+12*3^(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*D+27*D^2*A^2+4*D*B^3)^(1/
2)*A)^(1/3))]

The second and third of these involve imaginary numbers, so select
the first of them,

1/6/A*(36*C*B*A-108*D*A^2-8*B^3+12*3^(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*D+27*D^2
*A^2+4*D*B^3)^(1/2)*A)^(1/3)-2/3*(3*C*A-B^2)/A/(36*C*B*A-108*D*A^2-8*B^3+12*3^
(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*D+27*D^2*A^2+4*D*B^3)^(1/2)*A)^(1/3)-1/3*B/A

and substitute by comparison with the expanded cv3,

A = (-db+3*cv0*cr^2-3*db*cr+3*cv0*cr+cv0*cr^3-3*db*cr^2-db*cr^3+cv0)
B = (-2*db*cr^3+3*cv0-8*db*cr+3*p1*cr^2+p1-7*db*cr^2-3*db+p1*cr^3+3*p1*cr +
     3*cv0*cr^3+9*cv0*cr^2+9*cv0*cr)
C = (-3*db+3*cv0-4*db*cr^2+9*cv0*cr^2-db*cr^3-6*db*cr+9*cv0*cr +
     3*cv0*cr^3+2*p1+6*p1*cr+p2+6*p1*cr^2+2*p2*cr+2*p1*cr^3+p2*cr^2)
D = cv0+p2+p3+p1+p3*cr+cv0*cr^3+3*cv0*cr+3*p1*cr+3*p1*cr^2+2*p2*cr +
    p1*cr^3+3*cv0*cr^2+p2*cr^2

and you will have your multi-page solution.

(Somehow, I suspect that after seeing the multipage solution, you
will decide that maybe solving for x didn't turn out to be
very productive.)
-- 
   "Okay, buzzwords only. Two syllables, tops."  -- Laurie Anderson