#! mavscript --jasymca TEMPLATE.html

Example taken from the Jasymca manual

Exercise 10 (Plotting)

Plot the datapoints of the following table using plot and colored symbols. Calculate the linear regression using polyfit , and plot the regression line in the same graph. Add title and labels, and export the graphic to a file suitable for inclusion in a text document.


x

0 1 2 3 4 5 6 7 8 9

y

-3.1 -0.7 1.8 4.1 -6.2 8.9 11.3 13.5 16 18.3



Solution:

Input data

x=0:9 --> [ 0 1 2 3 4 5 6 7 8 9 ]

y=[-3.1,-0.7,1.8,4.1,6.2,8.9,11.3,13.5,16,18.3]

plot(x,y,"+r") % Symbol: o,x,+,*
hold % Current plot held.


Linear regression

c = polyfit(x,y,1) --> [ 2.3776 -3.0691 ]
equation: (2.3776) x + (-3.0691)

Y = polyval(c,x) --> [ -3.0691 -0.69152 1.6861 4.0636 6.4412 8.8188 11.196 13.574 15.952 18.329 ]

plot(x, Y)
xlabel("x-Achse")
ylabel("y-Achse")
title("Beispielgraph")
print("out-2-graph.eps")
print("out-2-graph.png")