Thread Subject: non-complex elements

Subject: non-complex elements

From: Steve

Date: 9 Feb, 2008 03:36:01

Message: 1 of 8

When using the 'solve' command, I am getting a solution
vector where I am only interested in the non-complex
element. How can I take only the real values of a vector?
Thanks.

Subject: non-complex elements

From: Shaun

Date: 9 Feb, 2008 03:58:06

Message: 2 of 8

lookfor real

Subject: non-complex elements

From: Steve

Date: 9 Feb, 2008 04:28:01

Message: 3 of 8

Well, there's isreal, of course, but I'd rather not loop
through each element and apply that command. There must be
a way to use the solve function to only give the real
solutions?

"Shaun " <s@s.com> wrote in message
<foj8ce$r3v$1@fred.mathworks.com>...
> lookfor real

Subject: non-complex elements

From: Shaun

Date: 9 Feb, 2008 04:57:01

Message: 4 of 8

>> x = roots([3 7 0 7 3])
x =
  -2.6180
   0.3333 + 0.9428i
   0.3333 - 0.9428i
  -0.3820
>> x(imag(x)==0)
ans =
   -2.6180
   -0.3820

Subject: non-complex elements

From: Steve

Date: 9 Feb, 2008 05:46:02

Message: 5 of 8

Ahh, see, I tried this to but no go. It must have something
to do with the 'solve' function?

EDU>> [x,y]=solve('2.8^2*32^2/10e3=x*y','y=x/10e3+(x/213)^4.5')
 
x =
 
 
41.722407862147426448707782826110-73.507292921775458350218631802263*i
 -59.669718037824467652279669253703+53.044012500010886727552493671779*i
 
41.722407862147426448707782826110+73.507292921775458350218631802263*i
                                     
66.677124117691249035503047088223
 -59.669718037824467652279669253703-53.044012500010886727552493671779*i
 
 
 
y =
 
 
.46885547030920421417850750011565e-2+.82603804909503165355563636007046e-2*i
 -.75153331228391432010200444372733e-2-.66808330459501486397430163934960e-2*i
 
.46885547030920421417850750011565e-2-.82603804909503165355563636007046e-2*i
                                        
.12040351329234836422099920311077e-1
 -.75153331228391432010200444372733e-2+.66808330459501486397430163934960e-2*i
 
 
EDU>> x(imag(x)==0)
 
ans =
 
[ empty sym ]
 
 
EDU>> y(imag(y)==0)
 
ans =
 
[ empty sym ]

"Shaun " <s@s.com> wrote in message
<fojbqt$e8m$1@fred.mathworks.com>...
> >> x = roots([3 7 0 7 3])
> x =
> -2.6180
> 0.3333 + 0.9428i
> 0.3333 - 0.9428i
> -0.3820
> >> x(imag(x)==0)
> ans =
> -2.6180
> -0.3820

Subject: non-complex elements

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 9 Feb, 2008 07:43:16

Message: 6 of 8

In article <foj731$a8d$1@fred.mathworks.com>,
Steve <steveDEL.bachmeierDEL@yahoo.com> wrote:
>When using the 'solve' command, I am getting a solution
>vector where I am only interested in the non-complex
>element. How can I take only the real values of a vector?

At the maple level, you would use rsolve. Placing assumptions
on your variables can also help, but even if all of your variables
are real, complex results can still be generated.

Selecting for Im(x) == 0 can be useful; though it would likely
be more useful to solve() for Im(x) = 0, as there might be
important conditions in which the imaginary term vanishes. The
presence of an imaginary term in a solution does not automatically
imply that the solution is non-real: such a solution might be
real (and distinct from the other solutions) under some conditions.
--
   "Beware of bugs in the above code; I have only proved it correct,
   not tried it." -- Donald Knuth

Subject: non-complex elements

From: Shaun

Date: 9 Feb, 2008 13:58:01

Message: 7 of 8

>> z = solve('3*x^4+7*x^3+7*x+3')
z =
   1/2*5^(1/2)-3/2
  -3/2-1/2*5^(1/2)
 1/3+2/3*i*2^(1/2)
 1/3-2/3*i*2^(1/2)
>> z = eval(z)
z =
  -0.3820
  -2.6180
   0.3333 + 0.9428i
   0.3333 - 0.9428i
>> z = z(imag(z)==0)
z =
   -0.3820
   -2.6180

Subject: non-complex elements

From: Steve

Date: 9 Feb, 2008 19:06:02

Message: 8 of 8

OK, thanks a lot; this seems to work. How come I have to
eval() the vectors first before imag()==0 will work?

"Shaun " <s@s.com> wrote in message
<fokbh9$1of$1@fred.mathworks.com>...
> >> z = solve('3*x^4+7*x^3+7*x+3')
> z =
> 1/2*5^(1/2)-3/2
> -3/2-1/2*5^(1/2)
> 1/3+2/3*i*2^(1/2)
> 1/3-2/3*i*2^(1/2)
> >> z = eval(z)
> z =
> -0.3820
> -2.6180
> 0.3333 + 0.9428i
> 0.3333 - 0.9428i
> >> z = z(imag(z)==0)
> z =
> -0.3820
> -2.6180

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
solve Steve 9 Feb, 2008 00:50:07
imag Steve 9 Feb, 2008 00:50:07
real Steve 9 Feb, 2008 00:50:07
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com