f(t)=a*cos(t+o)**2 + b*cos(t+o) + c
with gnuplot for different value of a, b, c, o values. In particular the parameters a, b, c, o have tabular form (in file data.dat):
a b c o
1 2 3 60
4 5 6 180
-3 -5 -9 -120
and t has range from
-180 to 180
for each row in data.dat file.
Can you help me? Thanks everyone.
Lucio
AFAIK it is not possible to have a "parameter file" with different parameters to plot in a function since the plot command can either take a function to plot or a datafile:
plot {<ranges>}
{<iteration>}
{<function> | {"<datafile>" {datafile-modifiers}}}
{axes <axes>} {<title-spec>} {with <style>}
{, {definitions{,}} <function> ...}
So either you have to create a datafile where your t
and functional values are listed for gnuplot to plot. An other workaround, that might be useful if you only have a limited number of karplus functions to plot is this:
set angles degrees
set xrange [-180:180]
f(x, a, b, c, o) = a*cos(x+o)**2 + b*cos(x+o) + c
title(n) = sprintf("f_%d", n)
plot a = 1 b = 2 c = 3 o = 60 f(x, a, b, c, o) t title(1), \
a = 4 b = 5 c = 6 o = 180 f(x, a, b, c, o) t title(2), \
a = -3 b = -5 c = -9 o = -120 f(x, a, b, c, o) t title(3)
Now you specify the parameters directly and and plot the function accordingly.
Alternatively you could implement an iteration like so:
plot for [a = 1:10:2] b = 2 c = 3 o = 60 f(x, a, b, c, o) t title(a)
Unfortunately it is not possible to nest iterations in gnuplot, so you have to cope with just having one parameter to vary.
If your first column was "t" (and "a" was your second column etc.), you could do:
plot "data.dat" u 1:($2*cos($1+$5)+$3*cos($1+$5)+$4)
Note the parens on the outside of what comes after the colon.
Not possible, as far as I know. What I do in this sort of case is to write a small script to generate the plot commands I need. For example, using awk
:
#! /usr/bin/env awk -f
BEGIN {
printf("plot ")
}
NR > 1 {
printf(" ,\\\n ")
}
{
printf("(%s) * cos(t+(%s))**2 + (%s) * cos(t+(%s)) + (%s)", $1, $4, $2, $4, $3)
}
END {
printf("\n")
}
Save that as a file karplus
and make it executable. Then ./karplus < data.dat
creates the plot command you need. Depending on your needs, a small makefile might be in order.
精彩评论