First time here? Check out the FAQ!

Ask Your Question
0

How can I solve this equation using SageMath?

asked 1 year ago

stonefaceq gravatar image

updated 0 years ago

FrédéricC gravatar image
#general solution
y = function('y')(x)
de = diff(y,x)*(4*x+2*y-3) - 2*x-y-1
solution = desolve(de, y)
solution.show()

#Cauchi problem solution
y=function('y')(x)
de = diff(y,x)*(4*x+2*y-3) - 2*x-y-1
solution=desolve(de,y,ics=[-2,1])
solution.show()
solution1=desolve(de,y,ics=[2,-1])
solution1.show()
solution2=desolve(de,y,ics=[1,1])
solution2.show()
solution3=desolve(de,y,ics=[-1,-1])
solution3.show()

#direction fields
x = var('x')
y = var('y')
f(x,y)= diff(y,x)*(4*x+2*y-3) - 2*x-y-1
p=plot_slope_field(f,(x,-10,10),(y,-10,10), headaxislength=5,
headlength=5,axes_labels=['$x$','$y(x)$'])

#plot of Cauchi problem solution
p+=desolve_rk4(f,y,ics=[-2,1],ivar=x,output='plot',
end_points=[-10,10],thickness=2,rgbcolor=hue(1))
p1=desolve_rk4(f,y,ics=[2,-1],ivar=x,output='plot',
end_points=[-10,10],thickness=2,rgbcolor=hue(0.2))
p2=desolve_rk4(f,y,ics=[1,1],ivar=x,output='plot',
end_points=[-10,10],thickness=2,rgbcolor=hue(0.5))
p3=desolve_rk4(f,y,ics=[-1,-1],ivar=x,output='plot',
end_points=[-10,10],thickness=2,rgbcolor=hue(0.3))
show(p+p1+p2+p3,xmin=-10,xmax=10,ymin=-10,ymax=10)
_____
NotImplementedError: Maxima was unable to solve this ODE. Consider to set option contrib_ode to True.

Here I want to find a solution for a differential equation, solve Cauchi problem and show direction fields. However, Sage can not solve it. It returns an error, showed in the code above. It is solved by hand. So, what can I possibly do?

Equation itself looks like this: (2x+y+1)dx - (4x+2y-3)dy = 0

Thank you

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 1 year ago

azerbajdzan gravatar image

The error tells you to set option... when done the equation is solved.

y = function('y')(x)
de = diff(y,x)*(4*x+2*y-3) - 2*x-y-1
solution = desolve(de, y,contrib_ode=True)
solution

[-1/5*(4*x + 2*y(x) - 3)*(log(1/(4*x + 2*y(x) - 3) + 1)/(4*x + 2*y(x) - 3) - log(1/(4*x + 2*y(x) - 3))/(4*x + 2*y(x) - 3) - 1) == _C + x]
Preview: (hide)
link

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: 1 year ago

Seen: 201 times

Last updated: Oct 20 '23