Message Boards Message Boards

Difference between "1" and "1." makes a change in BodePlot

Posted 10 years ago

I thought when I define a variable using "x=1" or "x=1.", the very difference is the resolution. But here is an interesting example bothering me. (1) Using "1."

T1 = 180*10^-6;
K1 = 1.;
sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*(Kpi + Kii/s)*1/(R + L s)
BodePlot[sysCL[3, 427.5, 0.285, 2*10^-3]]

(2) Using "1"

T1 = 180*10^-6;
K1 = 1;
sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*(Kpi + Kii/s)*1/(R + L s)
BodePlot[sysCL[3, 427.5, 0.285, 2*10^-3]]

The only difference between (1) and (2) is "1." and "1", but the result is totally different. See enter image description here

Can any one give an explanation?

POSTED BY: Seasong Zhang
12 Replies
Posted 10 years ago

Thanks a lot. If you get any useful infomation from Wolfram, can you publish it?

POSTED BY: Seasong Zhang

The underlying cause has been found. Developers are discussing the best way to fix it.

You might try Simplify or Expand on the expression (or its numerator) before plotting.

POSTED BY: Bruce Miller

Result expressions look as-expected in 10.0.0, but the third BodePlot has the extra hump. Strange. I will report it.

In[1]:= $Version

Out[1]= 10.0 for Mac OS X x86 (64-bit) (June 29, 2014)

In[2]:= T1 = 180*10^-6;
K1 = 1.;
sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*(Kpi + Kii/s)*1/(R + L s)
outA = sysCL[3, 427.5, 0.285, 2*10^-3]

Out[5]= 
             427.5
     1. (3 + -----)
               s
-------------------------
      9 s             s
(1 + -----) (0.285 + ---)
     50000           500

In[6]:= T1 = 180*10^-6;
K1 = 1.;
sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*((Kpi + Kii)/s)*1/(R + L s)
outB = sysCL[3, 427.5, 0.285, 2*10^-3]

Out[9]= 
           430.5
---------------------------
      9 s             s
(1 + -----) (0.285 + ---) s
     50000           500

In[10]:= T1 = 180*10^-6;
K1 = 1;
sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*(Kpi + Kii/s)*1/(R + L s)
outC = sysCL[3, 427.5, 0.285, 2*10^-3]

Out[13]= 
            427.5
        3 + -----
              s
-------------------------
      9 s             s
(1 + -----) (0.285 + ---)
     50000           500

In[14]:= T1 = 180*10^-6;
K1 = 1;
sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*((Kpi + Kii)/s)*1/(R + L s)
outD = sysCL[3, 427.5, 0.285, 2*10^-3]

Out[17]= 
          430.5
---------------------------
      9 s             s
(1 + -----) (0.285 + ---) s
     50000           500

enter image description here

POSTED BY: Bruce Miller
Anonymous User
Anonymous User
Posted 10 years ago

maybe there are tiny difference

No, Seasong Zhang they have no difference if you ask me. And they must have a huge difference easily visible to the eye as I show you in my computer result.

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 10 years ago

YES - Your problem is that your system and Mathematica mess up order of calculation in code line

sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*(Kpi + Kii/s)*1/(R + L s)

and interprets (Kpi+Kii/s) as ((Kpi+Kii)/s)

sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*((Kpi + Kii)/s)*1/(R + L s)

Answer

POSTED BY: Anonymous User
Posted 10 years ago

I'm with Mathematica 9. But I couldn't get your figures which could prove the calculating order problem. Instead, I got two same plots(maybe there are tiny difference. See enter image description here

POSTED BY: Seasong Zhang
Anonymous User
Anonymous User
Posted 10 years ago

Report for BUG Wolfram. Make new thread in Dashboard and titled it "Calculation order BUG in Mathematica 9..." They'll respond. Give link to these topic too.

If Mathematica 9 really have a such "calculation order bug", they will be grateful to you - because this is such a big problem that you can not even comprehend it.

I guess this problem is related to an undefined variable s that you use in function sysCL[] in some way.

Can you please make to me these 4 examples and show me results here:

T1 = 180*10^-6;
K1 = 1.;
sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*(Kpi + Kii/s)*1/(R + L s)
sysCL[3, 427.5, 0.285, 2*10^-3]

and

T1 = 180*10^-6;
K1 = 1.;
sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*((Kpi + Kii)/s)*1/(R + L s)
sysCL[3, 427.5, 0.285, 2*10^-3]

and

T1 = 180*10^-6;
K1 = 1;
sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*(Kpi + Kii/s)*1/(R + L s)
sysCL[3, 427.5, 0.285, 2*10^-3]

and

T1 = 180*10^-6;
K1 = 1;
sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*((Kpi + Kii)/s)*1/(R + L s)
sysCL[3, 427.5, 0.285, 2*10^-3]
POSTED BY: Anonymous User
Posted 10 years ago

Sorry to take 3 days to reply. There was something wrong with the reply button so that I couldn't make my reply.

Please check the pic.

enter image description here

There seems no bug of calculation order. However, check this. "Simplify" changes everything!!! enter image description here

And this

POSTED BY: Seasong Zhang
Anonymous User
Anonymous User
Posted 10 years ago

Can you test these two codes and show me result on your system:

T1 = 180*10^-6;
K1 = 1.;
sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*(Kpi + Kii/s)*1/(R + L s)
sysCL[3, 427.5, 0.285, 2*10^-3]

and this:

T1 = 180*10^-6;
K1 = 1;
sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*(Kpi + Kii/s)*1/(R + L s)
sysCL[3, 427.5, 0.285, 2*10^-3]

Are result like mine?

Test this

I have a filling that for some reason your system and Mathematica mess up order of calculation in code line when your K1 is 1 and 1.:

sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*(Kpi + Kii/s)*1/(R + L s)

If your result is like mine - probably there is a BUG in function BodePlot - report it to Wolfram. I'm with Mathematica 8 version.

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 10 years ago

My computer result - Wolfram Mathematica 8

Can you ask your friends to try my code once more?

I have no friends Seasong Zhang.

I run the code in 2 different computers and I get the same result.

I run the code in 2 different computers too - but result is the same for me, no difference.

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 10 years ago

What is difference between 1 and 1. you may see in these examples:

In[100]:= 1 + 3/5

Out[100]= 8/5

And next try with 1.

In[99]:= 1. + 3/5

Out[99]= 1.6

As you see in first example Mathematica try to give EXACT result because you don't use decimal point. When any number in an arithmetic expression is given with an explicit decimal point - as in your case 1. - you get an APPROXIMATE numerical result for the whole expression.

These APPROXIMATIONS in complex equations affect the output result just because they are approximations not exact numbers. End Result much depends what time of the complex calculations you serve your REQUEST FOR APPROXIMATION to Mathematica with some variable as "K1 = 1.;"

This topic is more like academic discussion than a simple answer.

P.s. In your concrete case I don't see any difference when I try it!

If the result is different obviously it matters whether you define in advance any of the variables as decimal point number or not. Like these two example.

In first case if you give whole number argument of f[] result will be exact.

Clear["Global`*"]
a = 2;
b = 5;
f[c_] := (a*b)/c;

In[172]:= f[3]

Out[172]= 10/3

In second case result will be approximation because a is 2.

Clear["Global`*"]
a = 2.;
b = 5;
f[c_] := (a*b)/c;

In[191]:= f[3]

Out[191]= 3.33333

but if use instead 3 argument 3. no matter what variable a is (2 or 2.) result will be approximation in the two cases.

Clear["Global`*"]
a = 2;
b = 5;
f[c_] := (a*b)/c;

In[209]:= f[3.]

Out[209]= 3.33333

and

Clear["Global`*"]
a = 2.;
b = 5;
f[c_] := (a*b)/c;

In[223]:= f[3.]

Out[223]= 3.33333

Do you understand?

In your case difference can be only if you use variables Kpi, Kii, R, L as exact numbers

For examples this result:

T1 = 180*10^-6;
K1 = 1;
sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*(Kpi + Kii/s)*1/(R + L s)
BodePlot[sysCL[3, 427, 2, 2*10^-3]]

will be different from this result:

T1 = 180*10^-6;
K1 = 1.;
sysCL[Kpi_, Kii_, R_, L_] := K1/(T1 s + 1)*(Kpi + Kii/s)*1/(R + L s)
BodePlot[sysCL[3, 427, 2, 2*10^-3]]
POSTED BY: Anonymous User
Posted 10 years ago

Thanks for your answer.

I knew the difference between "1." and "1" is related to the precision, like 0.3333 or 1/3.

But in the two cases, I got totally different results, more than the difference of precision. See the pic.

Can you ask your friends to try my code once more? I run the code in 2 different computers and I get the same result.

By the way, I couldn't reply to your reply in Chrome, but it seems OK in IE.

enter image description here

POSTED BY: Seasong Zhang
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract