Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to cancel out Im ?

Subject: how to cancel out Im ?

From: semiha

Date: 3 Apr, 2014 12:13:11

Message: 1 of 6

hi;
after i run a script, i get exp((t*i)/2 + x*i) - exp((t*i)/2 + x*i)/exp(Im(t) + 2*Im(x)) in command window. But i know that the result is zero and i defined x and t are symbolic (x and t are real) Is there easy way to deal with ?
Thanks for help

Subject: how to cancel out Im ?

From: Nasser M. Abbasi

Date: 3 Apr, 2014 13:11:16

Message: 2 of 6

On 4/3/2014 7:13 AM, semiha wrote:
> hi;
> after i run a script, i get exp((t*i)/2 + x*i) - exp((t*i)/2 + x*i)/exp(Im(t)
>+ 2*Im(x)) in command window. But i know that the result is zero and i
>defined x and t are symbolic (x and t are real) Is there easy way to deal with ?
> Thanks for help
>

what is "Im" in the above?

EDU>> help Im

Im not found.

Subject: how to cancel out Im ?

From: semiha

Date: 3 Apr, 2014 13:34:08

Message: 3 of 6

"Nasser M. Abbasi" wrote in message <lhjmlg$m3p$1@speranza.aioe.org>...
> On 4/3/2014 7:13 AM, semiha wrote:
> > hi;
> > after i run a script, i get exp((t*i)/2 + x*i) - exp((t*i)/2 + x*i)/exp(Im(t)
> >+ 2*Im(x)) in command window. But i know that the result is zero and i
> >defined x and t are symbolic (x and t are real) Is there easy way to deal with ?
> > Thanks for help
> >
>
> what is "Im" in the above?
>
> EDU>> help Im
>
> Im not found.
>

I can't understand exactly what Im is? Most probably imaginary part of x and imaginary part of t ? (but my both x and t are real)
my code :

clear all
clc

syms x t

a=1;
b=2;
e=1;
f=1;
c=real(sqrt((e-f-i*b)^2+4*(a)^2))
d=imag(sqrt((e-f-i*b)^2+4*(a)^2))

g=(-2*a*b)/((b)^2+(c)^2)
n=(-2*a*c)/((b)^2+(c)^2)
m=d/b


l=d*x-(b*c+(e+f)*d)*(t/2);
k=c*x-((e+f)*c-b*d)*(t/2);

psi=(a+(b*(g*cosh(l)+cos(k))/cosh(l)+g*cos(k))+(i*b*(n*sinh(l)+m*sin(k))/cosh(l)+g*cos(k)))*exp(i*(e*x+(a^2-(e^2/2))*t));


h= (1/2)* diff(psi,x,2)
s= i*diff(psi,t)
y= abs(psi).^2 * psi

son=h+s+y

Subject: how to cancel out Im ?

From: Steven Lord

Date: 3 Apr, 2014 13:36:13

Message: 4 of 6


"semiha " <ssemishh@hotmail.com> wrote in message
news:lhjj8n$ddn$1@newscl01ah.mathworks.com...
> hi;
> after i run a script, i get exp((t*i)/2 + x*i) - exp((t*i)/2 +
> x*i)/exp(Im(t) + 2*Im(x)) in command window. But i know that the result is
> zero and i defined x and t are symbolic (x and t are real) Is there easy
> way to deal with ? Thanks for help

Explicitly indicate that x and t are real when you define them to be
symbolic.

syms x t real

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: how to cancel out Im ?

From: Nasser M. Abbasi

Date: 3 Apr, 2014 13:44:41

Message: 5 of 6

On 4/3/2014 8:34 AM, semiha wrote:
> "Nasser M. Abbasi" wrote in message <lhjmlg$m3p$1@speranza.aioe.org>...
>> On 4/3/2014 7:13 AM, semiha wrote:
>>> hi;
>>> after i run a script, i get exp((t*i)/2 + x*i) - exp((t*i)/2 + x*i)/exp(Im(t)
>>> + 2*Im(x)) in command window. But i know that the result is zero and i
>>> defined x and t are symbolic (x and t are real) Is there easy way to deal with ?
>>> Thanks for help
>>>
>>
>> what is "Im" in the above?
>>
>> EDU>> help Im
>>
>> Im not found.
>>
>

> I can't understand exactly what Im is? Most probably imaginary part of x
>and imaginary part of t ? (but my both x and t are real)
> my code :
>
> clear all
> clc
>
> syms x t
>
> a=1;
> b=2;
> e=1;
> f=1;
> c=real(sqrt((e-f-i*b)^2+4*(a)^2))
> d=imag(sqrt((e-f-i*b)^2+4*(a)^2))
>
> g=(-2*a*b)/((b)^2+(c)^2)
> n=(-2*a*c)/((b)^2+(c)^2)
> m=d/b
>
>
> l=d*x-(b*c+(e+f)*d)*(t/2);
> k=c*x-((e+f)*c-b*d)*(t/2);
>
> psi=(a+(b*(g*cosh(l)+cos(k))/cosh(l)+g*cos(k))+(i*b*(n*sinh(l)+m*sin(k))/cosh(l)+g*cos(k)))*exp(i*(e*x+(a^2-(e^2/2))*t));
>
>
> h= (1/2)* diff(psi,x,2)
> s= i*diff(psi,t)
> y= abs(psi).^2 * psi
>
> son=h+s+y
>

That is strange. I run your code on Matlab 2013a and I do not see Im, I see imag:

son =
  
exp((t*i)/2 + x*i) - exp(- imag(t) - 2*imag(x))*exp((t*i)/2 + x*i)

Must be different version of Matlab

Try Steve suggestion, use:

  x = sym('x','real');
  t = sym('t','real');

now I get

      son=0

Subject: how to cancel out Im ?

From: semiha

Date: 3 Apr, 2014 13:47:08

Message: 6 of 6

Thank you, it works :)

Tags for this Thread

No tags are associated with this thread.

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.

Contact us