Python Forum
Laplace Inverse Transform Implementation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Laplace Inverse Transform Implementation
#1
Hello

My name is Jafar. In a part of my research I need to use DE HOOG inverse Laplace transform algorithm in Python.

I found a code from this link:


I am confused about how this code works as I am not an expert in python.
For example I do not know how I can define my function in Laplace domain in this code.


Lets say I need to find the inverse Laplace transform of the below function at t=1:

F(s) = 1/(s-1)

The inverse Laplace transform of F(s) is : e^(t)

At t=1 the result is expected to be =  e

This code starts with :


def HoogTransform(t, gamma, bigT, N, FUN, meth, init, d, work):

I think the parameter FUN should be where I have to define the the F(s). I tried that
but I could not get the code to work.

Could you please tell me how I can define F(s) in this code and how I can extract the result at t=1?
If it is not possible to get it to work and you know of any other simpler implementation of DE HOOG algorithm for inverse Laplace transform, I appreciate you to let me know.
Thanks in advance for your time and attention.
Best Regards
Jafar
Reply
#2
Please show your code with error
Reply
#3
This is the code with its documentation:



The thing is I have to define my function in the Laplace domain somewhere in this code. For example:

F(s) = 1/(s-1)

This code computes the inverse of F(s) which is :  
f(t)=e^t = e      (if t=1)


I don't know how I can define F(s) and extract the results for example at t=1.
Thanks in advance for your help.

Best
Jafar
Reply
#4
Ouch! Much more code than wanted. Is it possible to make a small snippet that will run and reproduce the error?
Looks like all indentation was lost
This shouldn't happer if you cut and paste fro, a properly formatted python script if you use cut and paste.
Reply
#5
when pasting, use [control] + [shift] + 'v'

yes, really don't need to see ~600 lines of comments. Please post the entire Traceback error as well.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#6
Thanks for your responses.
 I do not know how familiar you are with Laplace inverse transform. First of all we need to define a function in Laplace domain like:

 F(s) = 1 / (s-1)

After implementation of Laplace inverse we will have a function in the time-domain. For example the Laplace inverse of the above function is :

f(t) = e^t

I have seen a lot of other python codes (based on other algorithms) and in all of them there is a certain part for defining the F(s). For example:

#   The Laplace function F(s) is defined here.
def F(s):
    return 1.0 / (s - 1.0)
But there is no part in this code that the user can define the F(s). That is why I can not even run this code. (How am I supposed to get a error when I cant run the code?!).
Could you please take a closer look at this code and figure out how we can get it to work? Thanks again for your time.

Jafar
Reply
#7
I recently added some lines at the bottom of that code to define the F(s) and call the HoogTransform function from the code with its parameters. These are the 3 new lines I added at the end of the code:


#defining the F(s)=1/(s-1)
def FUN(s):
   return 1.0/(s-1.0)

#Calling the HoogTransform function
HoogTransform (1.0, 100, 20, 100, FUN, 3, 1, 10, 10)
And this is the complete code:
But I get this error:
Error:
Traceback (most recent call last):   File "/home/hp/Desktop/4.py", line 147, in <module>     HoogTransform (1.0, 100, 20, 100, FUN, 3, 1, 10, 10)   File "/home/hp/Desktop/4.py", line 46, in HoogTransform     d[0] = AOld TypeError: 'int' object does not support item assignment
Does anybody have any idea about how I can fix it and finally get the code to work?
Thanks
Reply
#8
HoogTransform (1.0, 100, 20, 100, FUN, 3, 1, 10, 10) ???
Where is this function?
Reply
#9
(Nov-16-2016, 12:07 AM)Larz60+ Wrote: HoogTransform (1.0, 100, 20, 100, FUN, 3, 1, 10, 10) ???
Where is this function?

Just click on the spoiler in my previous reply. Go to the line 5. This the function that returns the Laplace inverse of FUN. As you can see it includes different parameters. I just substitute the parameters with some arbitrary values. In addition I defined the FUN but it did not work. I am still confused about how this code works!
Reply
#10
(Nov-15-2016, 11:55 PM)jafar1363 Wrote: But I get this error:
Error:
Traceback (most recent call last):   File "/home/hp/Desktop/4.py", line 147, in <module>     HoogTransform (1.0, 100, 20, 100, FUN, 3, 1, 10, 10)   File "/home/hp/Desktop/4.py", line 46, in HoogTransform     d[0] = AOld TypeError: 'int' object does not support item assignment
Does anybody have any idea about how I can fix it and finally get the code to work?
Thanks

>>> d = 42
>>> d[0] = "spam"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object does not support item assignment
If you want "d" to be a list, you should make it a list, instead of the int it actually is.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] Looking for documentation on Reportlab's canvas.transform() function NeilUK 1 618 Aug-23-2023, 01:21 PM
Last Post: NeilUK
  Transform Dic to dataframe d9d9d 4 1,389 Apr-14-2022, 09:35 AM
Last Post: perfringo
  Transform 3 Columns into Single Column DaveG 8 1,889 Apr-04-2022, 08:42 AM
Last Post: Pedroski55
  How to transform from wide to long format in python shantanu97 1 1,659 Nov-21-2021, 11:53 AM
Last Post: buran
  How inverse a number? Capitaine_Flam 8 3,283 Nov-20-2020, 10:34 AM
Last Post: perfringo
  Transform list or set regardless of nesting structure blubb 2 1,970 Mar-10-2020, 07:17 PM
Last Post: ibreeden
  Transform simplified dictionary to nested dictionaries bhojendra 1 2,380 Jul-02-2019, 02:05 PM
Last Post: ichabod801
  transform list to tuple with takaa 2 2,855 Nov-28-2017, 10:44 PM
Last Post: takaa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020