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:
about complex number

Subject: about complex number

From: jyoti

Date: 1 Feb, 2012 17:56:09

Message: 1 of 5

hi,
i was sent previously code of my project.I am now correct and got a single drain current value for single Vds and Vgs.But the Ids i.e. drain to source current got a complex value.Some part code with some sequence of execution on command line are given below


>> pC = 2.0 * (xg - x_s) + Gf2 * (1.0 - Es + delta_1s * k_ds - delta_nd * (1.0 + xi1s))

pC =

  626.6728

>> qC = Gf2 * (1.0 - k_ds) * Ds

qC =

  2.5516e+005

>> temp = 2.0 - Gf2 * (Es + delta_1s * k_ds - delta_nd * xi2s)

temp =

     2

>> temp = pC * pC - 2.0 * (temp * qC)

temp =

 -6.2793e+005

>> sq=sqrt(temp)

sq =

        0 +7.9242e+002i

>> x_ds = 2.0 * (qC/sqpc)

x_ds =

  3.1334e+002 -3.9621e+002i

>>

In above case pC,qC, temp are not complex number it is (1X1 double), and sq and x_ds achieved was complex number.

Now i want a solution is that how a get answer without getting a complex number.
What is wrong with such coding actual whole code is more legthy so that i give some line maximum in my code 7 parameter face such problem.

plz help me to solve my problem

Subject: about complex number

From: Roger Stafford

Date: 1 Feb, 2012 19:22:10

Message: 2 of 5

"jyoti" wrote in message <jgbubp$ft$1@newscl01ah.mathworks.com>...
> temp =
> -6.2793e+005
> >> sq=sqrt(temp)
> sq =
> 0 +7.9242e+002i
>
> In above case pC,qC, temp are not complex number it is (1X1 double), and sq and x_ds achieved was complex number.
> Now i want a solution is that how a get answer without getting a complex number.
- - - - - - - - -
  I believe you have a misconception about complex numbers. Even though 'temp' is not complex, it is negative and when you take the square root of a negative real number the result is always complex. You will somehow have to arrange your computation so that 'temp' isn't negative when you call on 'sqrt' if you don't want complex results. This isn't an oddity with matlab, it is a fundamental property of basic mathematics.

Roger Stafford

Subject: about complex number

From: jyoti

Date: 2 Feb, 2012 14:43:10

Message: 3 of 5

"Roger Stafford" wrote in message <jgc3d2$htd$1@newscl01ah.mathworks.com>...
> "jyoti" wrote in message <jgbubp$ft$1@newscl01ah.mathworks.com>...
> > temp =
> > -6.2793e+005
> > >> sq=sqrt(temp)
> > sq =
> > 0 +7.9242e+002i
> >
> > In above case pC,qC, temp are not complex number it is (1X1 double), and sq and x_ds achieved was complex number.
> > Now i want a solution is that how a get answer without getting a complex number.
> - - - - - - - - -
> I believe you have a misconception about complex numbers. Even though 'temp' is not complex, it is negative and when you take the square root of a negative real number the result is always complex. You will somehow have to arrange your computation so that 'temp' isn't negative when you call on 'sqrt' if you don't want complex results. This isn't an oddity with matlab, it is a fundamental property of basic mathematics.
>
> Roger Stafford


Thanks,

but similar also occurs for subtraction for two numbers which are(1X1)double.
I will try my best computation

Subject: about complex number

From: dpb

Date: 2 Feb, 2012 15:30:01

Message: 4 of 5

On 2/1/2012 11:56 AM, jyoti wrote:

> i was sent previously code of my project.I am now correct and got a
> single drain current value for single Vds and Vgs.But the Ids i.e. drain
> to source current got a complex value.Some part code with some sequence
> of execution on command line are given below
>
>
> pC = 2*(xg-x_s)+Gf2*(1-Es+delta_1s*k_ds-delta_nd*(1+xi1s))
> pC = 626.6728
> qC = Gf2*(1.0-k_ds)*Ds
> qC = 2.5516e+005
> temp = 2-Gf2*(Es+delta_1s*k_ds-delta_nd*xi2s)
> temp = 2

I'll bet the above is a clue to where things have gone (badly) wrong...

The value of temp=2 above implies either Gf2==0 or the quantity
(Es+delta_1s*k_ds-delta_nd*xi2s)==0 and while you don't give the values
of all the intermediates, if the above code snippet is indeed complete
in the order given above then Gf2 can't be zero or gC would have been
zero. Therefore, one may presume that the other values in the
expression are zero or have a fortuitous cancellation to result in zero.

My days since semiconductors are too long gone to remember anything at
all regarding the models but I'm betting that the cause of the resulting
negative result in the next expression is that temp above was supposed
to be a number such that the subtrahend would be known to be less than
pC^2 --

> temp = pC*pC-2.0*(temp*qC)
> temp = -6.2793e+005
> sq=sqrt(temp)
...

> In above case pC,qC, temp are not complex number ...
...
> Now i want a solution is that how a get answer without getting a complex
> number.
> What is wrong with such coding ...
>
> plz help me to solve my problem

I'm pretty certain the problem is one related to the above--whether it
means you didn't enter an input value properly to cause the symptom or
the model isn't apropos to the application you're trying to use it for
or there is some error in the model itself is indeterminate here, of
course. Only you can know the basics of the problem you're trying to
solve and dig into the code and/or the input to it deeply enough to
understand where it went wrong...

But the complex number came because you took the square root of a
negative number as Roger notes and that came about because of the
relative magnitude of the values in the expression. Now your job is to
figure out whether it's the input to the model you have or the
application of the model to a problem for which it is not applicable or
there's simply an error in the model.

--

Subject: about complex number

From: Roger Stafford

Date: 2 Feb, 2012 18:49:09

Message: 5 of 5

"jyoti" wrote in message <jge7du$dth$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <jgc3d2$htd$1@newscl01ah.mathworks.com>...
> > "jyoti" wrote in message <jgbubp$ft$1@newscl01ah.mathworks.com>...
> > > In above case pC,qC, temp are not complex number it is (1X1 double), and sq and x_ds achieved was complex number.
> > > Now i want a solution is that how a get answer without getting a complex number.
> > - - - - - - - - -
> > I believe you have a misconception about complex numbers. ....
> > ......
> but similar also occurs for subtraction for two numbers which are(1X1)double.
> I will try my best computation
- - - - - - - - -
  No, you are mistaken. The sum, the difference, the product, and the quotient of a pair of real numbers are always themselves real (or indeterminate,) both in matlab and in the mathematical world.

  However, there are many other kinds of operations on real numbers that can produce complex values: polynomial roots, logarithms, trigonometric functions, inverse hyperbolic functions, etc. This is not a bad thing. Complex values have been a very important concept in mathematics and its applications ever since the sixteenth century. See:

 http://en.wikipedia.org/wiki/Complex_number

Roger Stafford

Tags for 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