Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Inverse Laplace in C++

Hi...
I'm efforting to write a program which computes the step answer of a system.
For this, I need inverse laplace class or code.
Can you help me?
Thanks
[175 byte] By [conteng] at [2007-11-11 8:36:00]
# 1 Re: Inverse Laplace in C++
If anybody knows this, please help me.
conteng at 2007-11-11 21:01:14 >
# 2 Re: Inverse Laplace in C++
I do not. Our equations do not change & we do these sorts of computations outside the code and put only the solution in code as an algebraic expression.
jonnin at 2007-11-11 21:02:14 >
# 3 Re: Inverse Laplace in C++
#include <iostream>
#include <cmath>
#include <complex>

using namespace std;

void InvLapTrans(complex<double> (*vs)(complex<double> s),double tstart,
double tend,double tdelta)
{
double t,vt;
int count;
static const complex<double> z[5] = {
complex<double>(11.83009373916819,1.593753005885813),
complex<double>(11.22085377939519,4.792964167565670),
complex<double>(9.933383722175002,8.033106334266296),
complex<double>(7.781146264464616,11.36889164904993),
complex<double>(4.234522494797000,14.95704378128156)};
static const complex<double> Kp[5] = {
complex<double>(16286.62368050479,-139074.7115516051),
complex<double>(-28178.11171305163,74357.58237274176),
complex<double>(14629.74025233142,-19181.80818501836),
complex<double>(-2870.418161032078,1674.109484084304),
complex<double>(132.1659412474876,17.47674798877164)};

t = tstart;
count = 0;
while (t <= tend) {
vt = 0.0;
for (int i=0;i<5;i++) {
vt = vt - real(vs(z[i] / t) * Kp[i]);
}
vt /= t;
cout<<count<<" "<<vt<<endl;
count++;
t += tdelta;
}
}

complex<double> vs(complex<double> s)
{

return 105.0 /((((s+10.0)*s+45.0)*s+105.0)*s+105.0);
}

I have this code. But I cannot call the return value from the main function. I want this: A user can enter the value which returns from the function. But I could not do this. s is a complex. How can I do this? Could anybody please help?
conteng at 2007-11-11 21:03:19 >
# 4 Re: Inverse Laplace in C++
Hi,

The problem is, that your function returns "void"

void InvLapTrans(complex<double> (*vs)(complex<double> s),double tstart,
double tend,double tdelta)
{
...
}

What you want is something

double InvLapTrans(complex<double> (*vs)(complex<double> s),double tstart,
double tend,double tdelta)
{
...

return vt;}

Cheers,

D
drkybelk at 2007-11-11 21:04:13 >