2

I am trying to approximation Graph(curve Fitting) for quadratic equation. I have 4 data File which contain x and y column.I determine coefficient and write each coefficient File for each data File.

clk0_h  clk0_h_c  clk0_s  clk0_s_c  clk1_h  clk1_h_c  clk1_s  clk1_s_c 
c coefficient File (As of now I determie manually for generate Graph in python)

The Graph I got is:enter image description here

The gnuplot code is:

set title "Approximation Graph"
set term png
set output 'plot.png'
f(x) = a*x*x + b*x + c
fit f(x) 'clk0_h' via 'clk0_h_c'
fit f(x) 'clk1_h' via 'clk1_h_c'
fit f(x) 'clk0_s' via 'clk0_s_c'
fit f(x) 'clk1_s' via 'clk1_s_c'
plot "clk0_h" using 1:2 with lines, f(x), "clk1_h" using 1:2 with lines, f(x), "clk0_s" using 1:2 with lines, f(x), "clk1_s" using 1:2 with lines, f(x)

I am trying to approximation graph of each line. But it looks like, it has mixed or overwrite. I need to create following Graph using gnuplot.I know, I am very far from original graph. But Can I know, Can be create scatter graph using gnuplot.

In the below graph, dash line represent the approximation ( for sample represent in two only) But In working Graph, we need four approximation line.

enter image description here

I tried gnuplot today only and need to create graph also.

1 Answer 1

1

You always fit the same function f(x) with different start values, given in the coefficient files. In order to have four different functions, you must also define those four distinct functions:

f0_h(x) = a0_h * x**2 + b0_h * x + c0_h
fit f0_h(x) 'clk0_h' via 'clk0_h_c'

f1_h(x) = a1_h * x**2 + b1_h * x + c1_h
fit f1_h(x) 'clk1_h' via 'clk1_h_c'

f0_s(x) = a0_s * x**2 + b0_s * x + c0_s
fit f0_s(x) 'clk0_s' via 'clk0_s_c'

f1_s(x) = a1_s * x**2 + b1_s * x + c1_s
fit f1_s(x) 'clk1_s' via 'clk1_s_c'

set style data lines
plot 'clk0_h' u 1:2, f0_h(x), \
     'clk1_h' u 1:2, f1_h(x), \
     'clk0_s' u 1:2, f0_s(x), \
     'clk1_s' u 1:2, f1_s(x)

Accordingly, your coefficient file must also contain different parameter definitions (using a0_h etc.).

If you want to keep the coefficient files to have the same format (use only a, b, and c), you can use one function f(x) for fitting, and then assign the fitted variables to the concrete functions which are to be plotted:

f(x) = a * x**2 + b * x + c
f0_h(x) = a0_h * x**2 + b0_h * x + c0_h
f1_h(x) = a1_h * x**2 + b1_h * x + c1_h
f0_s(x) = a0_s * x**2 + b0_s * x + c0_s
f1_s(x) = a1_s * x**2 + b1_s * x + c1_s

fit f0_h(x) 'clk0_h' via 'clk0_h_c'
a0_h = a; b0_h = b; c0_h = c;

fit f1_h(x) 'clk1_h' via 'clk1_h_c'
a1_h = a; b1_h = b; c1_h = c;

fit f0_s(x) 'clk0_s' via 'clk0_s_c'
a0_s = a; b0_s = b; c0_s = c;

fit f1_s(x) 'clk1_s' via 'clk1_s_c'
a1_s = a; b1_s = b; c1_s = c;

set style data lines
plot 'clk0_h' u 1:2, f0_h(x), \
     'clk1_h' u 1:2, f1_h(x), \
     'clk0_s' u 1:2, f0_s(x), \
     'clk1_s' u 1:2, f1_s(x)
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot for your response. Can We create scatter graph also in Gnuplot.if Yes Can you give me some idea to generate scatter graph
Well, the easiest possiblity for a scatter plot is splot 'data.txt' with points. If you have some special needs, I would suggest you to ask a new question.
Really it is ton of thanks when u have very limited time and you got appropriate input

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.