var('t','x','y') #Define your variables
r(t) = (t,4-t^2) #State your parametrization
bounds = (t,-1,2) #Give bounds for the parametrization
F(x,y) = (2*x+y,-x) #State the vector field
xbounds = (x,-1,2) #These bounds are useful if you want to make a good plot.
ybounds = (y,0,4) #These bounds are useful if you want to make a good plot.
dr = r.diff(t) #Compute the derivative
dW=F(*r(t)).dot_product(dr(t)) #Find a little bit of work. The code r[0] gives the first component, and r[1] gives the second.
W=integrate(dW,bounds)
pretty_print(html("""The work done by $F=%s$ along the curve r=$%s$
over the bounds $%s$ is $%s$"""%tuple(map(latex, [F(x,y), r(t), bounds, W]))))
show(table([
[r"$\vec r(t)$", "$(x,y)$", r(t)],
[r"$d\vec r$", "$(dx,dy)$", dr(t)],
["$F(x,y)$", F(x,y), F(*r(t))],
["$M$", F(x,y)[0], F(*r(t))[0]],
["$N$", F(x,y)[1], F(*r(t))[1]],
[r"$dW=F\cdot d\vec r$", "$Mdx+Ndy$", dW],
[r"$W=\int_C F\cdot d\vec r$",W,W]
]
))
p=parametric_plot(r(t),bounds)
p+=plot_vector_field(F,xbounds,ybounds)
show(p)