A problem with ilaplace()

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

A problem with ilaplace()

Leo Baumann
Hello folks,

I have reduced the problem. -

It is explained in Octave script:

#--------------------------------------------------------------------------

clc;
clear all;
pkg load symbolic;
syms p t;

#a few simple calculations
Rgen=50;C1=100e-9;Rlast=50;
fg=10e3;
R1=1/(2*pi*10e3*C1)-Rgen;
wg=2*pi*fg;

#this works fine, Tp1 is a simple imagined example ...
Tp1=1/(5*p+6);
laplace1=1/p*Tp1;
ux=function_handle(ilaplace(laplace1, p, t));

#this doesn't work, I don't understand that because Tp2 is the same
#as the example with other numbers
Tp2=1/(1+(Rgen+R1)/Rlast+p*C1*(Rgen+R1));
laplace2=1/p*Tp2;
ux=function_handle(ilaplace(laplace2, p, t));

#----------------------------------------------------------------------------------------

I don't understand that the second example doesn't work, all variables
are defined.

Any hint?

Thanks - Leo


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: A problem with ilaplace()

Doug Stewart-4


On Tue, Nov 14, 2017 at 9:47 AM, Leo Baumann <[hidden email]> wrote:
Hello folks,

I have reduced the problem. -

It is explained in Octave script:

#--------------------------------------------------------------------------

clc;
clear all;
pkg load symbolic;
syms p t;

#a few simple calculations
Rgen=50;C1=100e-9;Rlast=50;
fg=10e3;
R1=1/(2*pi*10e3*C1)-Rgen;
wg=2*pi*fg;

#this works fine, Tp1 is a simple imagined example ...
Tp1=1/(5*p+6);
laplace1=1/p*Tp1;
ux=function_handle(ilaplace(laplace1, p, t));

#this doesn't work, I don't understand that because Tp2 is the same
#as the example with other numbers
Tp2=1/(1+(Rgen+R1)/Rlast+p*C1*(Rgen+R1));
laplace2=1/p*Tp2;
ux=function_handle(ilaplace(laplace2, p, t));

#----------------------------------------------------------------------------------------

I don't understand that the second example doesn't work, all variables are defined.

Any hint?

Thanks - Leo


Hi Leo:

Yes I can reproduce your problem. It does seem strange that the symbolics pkg can give
a nice answer to the simple example and not give an answer to the real example.

If you really want a symbolic answer then Xmaxima is one way to do it;

here is maxima's answer:
(%i14)  Tp2:1/(1+(Rgen+R1)/Rlast+p*C1*(Rgen+R1));
                                                                                        1
(%o14)                                                                   --------------------------------
                                                                                            Rgen + R1
                                                                         p C1 (Rgen + R1) + --------- + 1
                                                                                              Rlast
(%i15) ll:laplace2:1/p*Tp2;
                                                                                        1
(%o15)                                                                 ------------------------------------
                                                                                             Rgen + R1
                                                                       p (p C1 (Rgen + R1) + --------- + 1)
                                                                                               Rlast
(%i16) ilt(ll,p,t);
                                                                                                          t (Rgen + Rlast + R1)
                                                                                                     - ---------------------------
                                                                              2           2            Rlast C1 R1 + Rgen Rlast C1
                                                     Rlast         (Rgen Rlast  C1 + Rlast  C1 R1) %e
(%o16)                                         ----------------- - ---------------------------------------------------------------
                                               R1 + Rlast + Rgen          (R1 + Rlast + Rgen) (Rlast C1 R1 + Rgen Rlast C1)



some of the formatting gets warped but you can try the commands yourself in Xmaxima.

Doug


--
DAS


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: A problem with ilaplace()

Doug Stewart-4
In reply to this post by Leo Baumann


On Tue, Nov 14, 2017 at 9:47 AM, Leo Baumann <[hidden email]> wrote:
Hello folks,

I have reduced the problem. -

It is explained in Octave script:

#--------------------------------------------------------------------------

clc;
clear all;
pkg load symbolic;
syms p t;

#a few simple calculations
Rgen=50;C1=100e-9;Rlast=50;
fg=10e3;
R1=1/(2*pi*10e3*C1)-Rgen;
wg=2*pi*fg;

#this works fine, Tp1 is a simple imagined example ...
Tp1=1/(5*p+6);
laplace1=1/p*Tp1;
ux=function_handle(ilaplace(laplace1, p, t));

#this doesn't work, I don't understand that because Tp2 is the same
#as the example with other numbers
Tp2=1/(1+(Rgen+R1)/Rlast+p*C1*(Rgen+R1));
laplace2=1/p*Tp2;
ux=function_handle(ilaplace(laplace2, p, t));

#----------------------------------------------------------------------------------------

I don't understand that the second example doesn't work, all variables are defined.

Any hint?

Thanks - Leo


_
What results are you looking for. What is your overall goal?


--
DAS


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: A problem with ilaplace()

Leo Baumann
In reply to this post by Doug Stewart-4
Am 14.11.2017 um 18:16 schrieb Doug Stewart:


On Tue, Nov 14, 2017 at 9:47 AM, Leo Baumann <[hidden email]> wrote:
Hello folks,

I have reduced the problem. -

It is explained in Octave script:

#--------------------------------------------------------------------------

clc;
clear all;
pkg load symbolic;
syms p t;

#a few simple calculations
Rgen=50;C1=100e-9;Rlast=50;
fg=10e3;
R1=1/(2*pi*10e3*C1)-Rgen;
wg=2*pi*fg;

#this works fine, Tp1 is a simple imagined example ...
Tp1=1/(5*p+6);
laplace1=1/p*Tp1;
ux=function_handle(ilaplace(laplace1, p, t));

#this doesn't work, I don't understand that because Tp2 is the same
#as the example with other numbers
Tp2=1/(1+(Rgen+R1)/Rlast+p*C1*(Rgen+R1));
laplace2=1/p*Tp2;
ux=function_handle(ilaplace(laplace2, p, t));

#----------------------------------------------------------------------------------------

I don't understand that the second example doesn't work, all variables are defined.

Any hint?

Thanks - Leo


Hi Leo:

Yes I can reproduce your problem. It does seem strange that the symbolics pkg can give
a nice answer to the simple example and not give an answer to the real example.

If you really want a symbolic answer then Xmaxima is one way to do it;

here is maxima's answer:
(%i14)  Tp2:1/(1+(Rgen+R1)/Rlast+p*C1*(Rgen+R1));
                                                                                        1
(%o14)                                                                   --------------------------------
                                                                                            Rgen + R1
                                                                         p C1 (Rgen + R1) + --------- + 1
                                                                                              Rlast
(%i15) ll:laplace2:1/p*Tp2;
                                                                                        1
(%o15)                                                                 ------------------------------------
                                                                                             Rgen + R1
                                                                       p (p C1 (Rgen + R1) + --------- + 1)
                                                                                               Rlast
(%i16) ilt(ll,p,t);
                                                                                                          t (Rgen + Rlast + R1)
                                                                                                     - ---------------------------
                                                                              2           2            Rlast C1 R1 + Rgen Rlast C1
                                                     Rlast         (Rgen Rlast  C1 + Rlast  C1 R1) %e
(%o16)                                         ----------------- - ---------------------------------------------------------------
                                               R1 + Rlast + Rgen          (R1 + Rlast + Rgen) (Rlast C1 R1 + Rgen Rlast C1)



some of the formatting gets warped but you can try the commands yourself in Xmaxima.

Doug


--
DAS


Hello Doug,
thanks - I understand what You have written. Maxima is another computer algebra system. -
I think You want to say that Octave-Symbolic cannot solve my problem. -
Ok - thanks - I will do a few tests and try it.

Regards Leo

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: A problem with ilaplace()

Leo Baumann
In reply to this post by Doug Stewart-4
Am 14.11.2017 um 18:22 schrieb Doug Stewart:


On Tue, Nov 14, 2017 at 9:47 AM, Leo Baumann <[hidden email]> wrote:
Hello folks,

I have reduced the problem. -

It is explained in Octave script:

#--------------------------------------------------------------------------

clc;
clear all;
pkg load symbolic;
syms p t;

#a few simple calculations
Rgen=50;C1=100e-9;Rlast=50;
fg=10e3;
R1=1/(2*pi*10e3*C1)-Rgen;
wg=2*pi*fg;

#this works fine, Tp1 is a simple imagined example ...
Tp1=1/(5*p+6);
laplace1=1/p*Tp1;
ux=function_handle(ilaplace(laplace1, p, t));

#this doesn't work, I don't understand that because Tp2 is the same
#as the example with other numbers
Tp2=1/(1+(Rgen+R1)/Rlast+p*C1*(Rgen+R1));
laplace2=1/p*Tp2;
ux=function_handle(ilaplace(laplace2, p, t));

#----------------------------------------------------------------------------------------

I don't understand that the second example doesn't work, all variables are defined.

Any hint?

Thanks - Leo


_
What results are you looking for. What is your overall goal?

At the moment my script makes no use. I was preparing a general usable script to evaluate step function responses for electric networks. I could do that numeric with following Octave function, but the symbolic answer is much more interesting. -

# Talbot suggested that the Bromwich line be deformed into a contour that begins
# and ends in the left half plane, i.e., z ? -8 at both ends.
# Due to the exponential factor the integrand decays rapidly
# on such a contour. In such situations the trapezoidal rule converge
# extraordinarily rapidly.
# For example here we compute the inverse transform of F(s) = 1/(s+1) at t = 1
#-----------------------------------------------------------------------------
#>> pkg load symbolic
#>> syms s
#>> F=1/(s+1)
#F = (sym)
#
#    1
#  -----
#  s + 1
#
#>> error=talbot(function_handle(F),1,24)-exp(-1)
#ans =   1.6098e-015
#-------------------------------------------------------------------------------
#
# Talbot method is very powerful here we see an error of 1.61e-015
# with only 24 function evaluations
#
# Created by Fernando Damian Nieuwveldt     
# [hidden email]
# Date : 25 October 2009
#
# Reference
# L.N.Trefethen, J.A.C.Weideman, and T.Schmelzer. Talbot quadratures
# and rational approximations. BIT. Numerical Mathematics,
# 46(3):653 670, 2006.

function ilt = talbot(f_s, t, N)
h=2*pi/N;

#   Shift contour to the right in case there is a pole on the positive real axis : Note the contour will
#   not be optimal since it was originally devoloped for function with
#   singularities on the negative real axis
#   For example take F(s) = 1/(s-1), it has a pole at s = 1, the contour needs to be shifted with one
#   unit, i.e shift  = 1. But in the test example no shifting is necessary
 shift=0;

 ans=0;
 for k=0:N
   theta=-pi+(k+1/2)*h;
   z=shift+N/t*(0.5017*theta*cot(0.6407*theta)-0.6122+0.2645i*theta);
   dz=N/t*(-0.5017*0.6407*theta/sin(0.6407*theta)^2+0.5017*cot(0.6407*theta)+0.2645i);
   ans=ans+exp(z*t)*f_s(z)*dz;
 endfor
   ilt=real((h/(2i*pi))*ans);
endfunction

Regards - Leo

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: A problem with ilaplace()

Leo Baumann
In reply to this post by Doug Stewart-4
Am 14.11.2017 um 18:22 schrieb Doug Stewart:


On Tue, Nov 14, 2017 at 9:47 AM, Leo Baumann <[hidden email]> wrote:
Hello folks,

I have reduced the problem. -

It is explained in Octave script:

#--------------------------------------------------------------------------

clc;
clear all;
pkg load symbolic;
syms p t;

#a few simple calculations
Rgen=50;C1=100e-9;Rlast=50;
fg=10e3;
R1=1/(2*pi*10e3*C1)-Rgen;
wg=2*pi*fg;

#this works fine, Tp1 is a simple imagined example ...
Tp1=1/(5*p+6);
laplace1=1/p*Tp1;
ux=function_handle(ilaplace(laplace1, p, t));

#this doesn't work, I don't understand that because Tp2 is the same
#as the example with other numbers
Tp2=1/(1+(Rgen+R1)/Rlast+p*C1*(Rgen+R1));
laplace2=1/p*Tp2;
ux=function_handle(ilaplace(laplace2, p, t));

#----------------------------------------------------------------------------------------

I don't understand that the second example doesn't work, all variables are defined.

Any hint?

Thanks - Leo


_
What results are you looking for. What is your overall goal?

Doug, I found a solution for Octave. Watch the script, please :)

#-------------------------------------------------------------------------------------
clc;
clear all;
pkg load symbolic;
syms p t;

#a few simple calculations
Rgen=50;C1=100e-9;Rlast=50;
fg=10e3;
R1=1/(2*pi*10e3 *C1)-Rgen;
wg=2*pi*fg;
a=5.3;b=7.1;

#this works fine, Tp1 is a simple imagined example ...
Tp1=1/(p*a+b);
laplace1=1/p*Tp1;
ux1=function_handle(ilaplace(laplace1, p, t));

#this works now, too - I have made the coefficient of p in the denominator of Tp2 to 1
c=C1*(Rgen+R1);d=1+(Rgen+R1)/Rlast;
Tp2=1/c/(p+d/c);
laplace2=1/p*Tp2;
ux2=function_handle(ilaplace(laplace2, p, t));
#--------------------------------------------------------------------------------------------------------------

It works if the coefficient of p in the denominator of Tp2 is 1.

Regards - Leo

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: A problem with ilaplace()

Doug Stewart-4
In reply to this post by Leo Baumann

At the moment my script makes no use. I was preparing a general usable script to evaluate step function responses for electric networks. I could do that numeric with following Octave function, but the symbolic answer is much more interesting. -

Are you aware of the step function in the control package?

 s=tf('s')
plant= 24/(s^2 +3*s +24)
step(plant)


all from laplace space.

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: A problem with ilaplace()

Colin Macdonald-2
In reply to this post by Leo Baumann
On 2017-11-14 10:34 AM, Leo Baumann wrote:
> It works if the coefficient of p in the denominator of Tp2 is 1.

Thanks Leo and Doug.  I played with this a bit, it seems simply 1/poly
with poles in left-half plane are very slow (when they should be easy).
I filed an issue upstream with "Sympy" (which the symbolic package uses).

https://github.com/sympy/sympy/issues/13606

Feel free to follow along if you wish.  I think transforms are an area
where Sympy is particularly poor so lots of chances to help out if you
can spare the time!

Finally, note the value of reducing things to the simplest possible
example---I'm playing with ilaplace(1/((p+1)(p+10)), p, t).  People are
much more likely to help with your problem if its not full of R1, Rlast
etc numbers.

best,
Colin

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: A problem with ilaplace()

Leo Baumann
In reply to this post by Doug Stewart-4
Am 14.11.2017 um 19:47 schrieb Doug Stewart:

At the moment my script makes no use. I was preparing a general usable script to evaluate step function responses for electric networks. I could do that numeric with following Octave function, but the symbolic answer is much more interesting. -

Are you aware of the step function in the control package?

 s=tf('s')
plant= 24/(s^2 +3*s +24)
step(plant)


all from laplace space.
No, that is new fro me - I will learn it :)
thanks
Regards - Leo

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: A problem with ilaplace()

Doug Stewart-4

Try this:

p=tf('s')

#a few simple calculations
Rgen=50;C1=100e-9;Rlast=50;
fg=10e3;
R1=1/(2*3*10e3*C1)-Rgen;
wg=2*3*fg;

#this works fine, Tp1 is a simple imagined example ...
Tp1=1/(5*p+6)
laplace1=1/p*Tp1

figure(1)
step(laplace1)



#this doesn't work, I don't understand that because Tp2 is the same
#as the example with other numbers
Tp2=1/(1+(Rgen+R1)/Rlast+p*C1*(Rgen+R1))


laplace2=1/p*Tp2
figure(2)
step(laplace2)

#since you have a pole at the origin then the output keeps getting larger.


#try this
figure(3)
step(Tp2)

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave