Ask Your Question
0

curve fitting coefficients.

asked 2016-01-04 19:36:40 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

get the model coefficients, but I can not use them to plot the graph. How to solve?

see the code:

dados = [(0, -0.183440428023042),
 (0.200000000000000, -0.131101157495126),
 (0.400000000000000, 0.0268875670852843),
 (0.800000000000000, 0.110532679260319),
 (1.00000000000000, 0.253944632998395),
 (1.20000000000000, 0.257190123748649),
 (1.40000000000000, 0.531888837111346),
 (1.60000000000000, 0.579048247883555),
 (2.00000000000000, 0.935180993484717),
 (2.20000000000000, 0.916600344376623),
 (2.60000000000000, 1.13328608090532),
 (2.80000000000000, 1.26893326843583),
 (3.00000000000000, 1.10202945535186),
 (3.40000000000000, 1.13391615491257)]

point(dados,color = "red",size=20,legend_label="pontos coletados")

modelo(x) = a*x+b;modelo

a,b = find_fit(dados, modelo);a;b

modelo(x) = a*x+b

point(dados,color = "red",size=20,legend_label="pontos coletados") + plot(modelo(x),(x,0,3))
Traceback (click to the left of this block for traceback)
...
ValueError: Variable 'x' not found
edit retag flag offensive close merge delete

Comments

What are 'a' and 'b'? Did you define them as variables?

vdelecroix gravatar imagevdelecroix ( 2016-01-04 20:42:43 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-01-04 20:46:39 +0200

vdelecroix gravatar image

You should do

sage: a,b = var('a', 'b')
sage: modelo(x) = a*x+b
sage: print modelo
x |--> a*x + b
sage: d = find_fit(dados, modelo, solution_dict=True)
sage: print d
{b: -0.1757321718542446, a: 0.4599622663189693}
sage: modelo2 = modelo.subs(d)
sage: print modelo2
x |--> 0.4599622663189693*x - 0.1757321718542446
sage: point(dados,color = "red",size=20,legend_label="pontos coletados") + plot(modelo2,(x,0,3))

In your code, the variable does not get substituted as expected. You can see it by printing what is modelo.

edit flag offensive delete link more

Comments

hello vdelecroix Thank you for your help ;). Now it works correctly.

jmarcellopereira gravatar imagejmarcellopereira ( 2016-01-04 23:00:43 +0200 )edit

@jmarcellopereira De nada! If you are satisfied with my answer, you can select it with the check box that appear on its left ("mark this answer as correct"). That way this question will appeared as "solved" in the list of questions.

vdelecroix gravatar imagevdelecroix ( 2016-01-05 02:28:51 +0200 )edit

marked ;)

jmarcellopereira gravatar imagejmarcellopereira ( 2016-01-05 03:49:14 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-01-04 19:36:40 +0200

Seen: 754 times

Last updated: Jan 04 '16