#! 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

§m x=0:9 §io

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

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


Linear regression

§m c = polyfit(x,y,1) §io
equation: (§m c(1) §o) x + (§m c(2) §o)

§m Y = polyval(c,x) §io

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