I would like to plot an IR-spectrum. The problem is,
that I have only the datapoints of the intensity and
wavenumber at the maximum, e.g.
# spectrum.dat
# v I
0.00 0.00
108.97 0.00
169.61 6.21
325.48 0.00
486.67 183.07
so I would need to fit a Lorentzian function to each
datapoint-pair
f(x) = alpha*I_(1strow)/(pi*alpha*(x-v_(1strow))**2+1)
g(x) = alpha*I_(2ndrow)/(pi*alpha*(x-v_(2ndrow))**2+1)
.
.
.
z(x) = alpha*I_(last-row)/(pi*alpha*(x-v_(last-row))**2+1)
and then sum all functions to obtain the spectrum. Is
this possible with gnuplot? How?
Thanks
Philipp Eiden
I don't have time to think this through completely but one way would
be call an awk script that parsed each line into gnuplot set
commands , eg:
v_2 =169.61; l_2 =6.21
or more directly, your function definitions. Call the script from
gnuplot (help system) then read the output into gnuplot with load
command and plot f(x)+g(x)....+z(x)
$0 is the line counter for gnuplot data but I can't think of a clean
way to use that to be part of a varable name.
You will obviously need to make sure your data are valid : (0,0) ?!!
How does it look?
> so I would need to fit a Lorentzian function to each
> datapoint-pair
>
> f(x) = alpha*I_(1strow)/(pi*alpha*(x-v_(1strow))**2+1)
> g(x) = alpha*I_(2ndrow)/(pi*alpha*(x-v_(2ndrow))**2+1)
>
What is alpha? Is the first column v_(nth_row). Or the other way around?
--
Rahul
> # spectrum.dat
> # v I
> 0.00 0.00
> 108.97 0.00
> 169.61 6.21
> 325.48 0.00
> 486.67 183.07
>
> so I would need to fit a Lorentzian function to each datapoint-pair
Erm, no. That:
> f(x) = alpha*I_(1strow)/(pi*alpha*(x-v_(1strow))**2+1)
is not a fit. That's just the function with the given parameters.
> and then sum all functions to obtain the spectrum. Is this possible with
> gnuplot?
It might be possible with the current development version, but at the
bottom of it, gnuplot is not the right tool for this job. For number
crunching, use a number crunching tool. Octave should work just fine.
reading in two parameters and plotting a standard function can hardly
be called number crunching even if it is repeated for several pairs of
parameters. Gnuplot is a plotting program and plotting such functions
would seem to be very much what it is intended to do.
it's not a question of number cruching just a case of reading in a
small number of parameter constants and plotting the function.
can you see a way to name a variable from $0 ?
#! /usr/bin/awk -f
BEGIN {line=0}
($0 !~ /^#/)&&($0 != "") {
print "f"line"(x)=alpha*"$1"/(pi(x-"$2")**2+1)\n"
}
in gnuplot :
load << system(lorenz.sh)
Debug the syntax yourself , I ain't going to do the whole job for you,
but that should do what you want in an efficient manner.
Thanks for your effort.
oops , I forgot to increment "line" . I warned you it would need
debuggin , I was in a rush but at least it wasn't far off. Glad it
gave you what you wanted.
It always amazes me what you can do with gnuplot ( and maybe a little
help from awk).
best