Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for Scripts for computer labs M1VM01 and M5858.
Download
36 views
ubuntu2204
Kernel: SageMath 10.6
# Proměnné a funkce t = var('t') x = function('x')(t)
# ODE ode = diff(x, t) == x - x^3
# Analytické řešení ODE s počáteční podmínkou x(0)=1/2 sol = desolve(ode, x, ics=[0, 1/2]) show(sol)

12log(x(t)+1)12log(x(t)1)+log(x(t))=12iπ+tlog(2)12log(32)12log(12)\displaystyle -\frac{1}{2} \, \log\left(x\left(t\right) + 1\right) - \frac{1}{2} \, \log\left(x\left(t\right) - 1\right) + \log\left(x\left(t\right)\right) = -\frac{1}{2} i \, \pi + t - \log\left(2\right) - \frac{1}{2} \, \log\left(\frac{3}{2}\right) - \frac{1}{2} \, \log\left(\frac{1}{2}\right)

sol_exp = solve(sol, x) show(sol_exp)

[log(x(t))=12iπ+t12log(2)12log(32)+12log(x(t)+1)+12log(x(t)1)]\displaystyle \left[\log\left(x\left(t\right)\right) = -\frac{1}{2} i \, \pi + t - \frac{1}{2} \, \log\left(2\right) - \frac{1}{2} \, \log\left(\frac{3}{2}\right) + \frac{1}{2} \, \log\left(x\left(t\right) + 1\right) + \frac{1}{2} \, \log\left(x\left(t\right) - 1\right)\right]

# "Ruční" separace proměnných a integrace x_var = var('x') integrand = 1/(x_var - x_var^3) parfrac = integrand.partial_fraction(x_var) show(parfrac) integral_x = integrate(parfrac, x_var) show(integral_x) integral_t = integrate(1, t) show(integral_t) c = var('c') rce = integral_x == t + c show(rce)

12(x+1)12(x1)+1x\displaystyle -\frac{1}{2 \, {\left(x + 1\right)}} - \frac{1}{2 \, {\left(x - 1\right)}} + \frac{1}{x}

12log(x+1)12log(x1)+log(x)\displaystyle -\frac{1}{2} \, \log\left(x + 1\right) - \frac{1}{2} \, \log\left(x - 1\right) + \log\left(x\right)

t\displaystyle t

12log(x+1)12log(x1)+log(x)=c+t\displaystyle -\frac{1}{2} \, \log\left(x + 1\right) - \frac{1}{2} \, \log\left(x - 1\right) + \log\left(x\right) = c + t

str(rce)
'-1/2*log(x + 1) - 1/2*log(x - 1) + log(x) == c + t'
eq=-1/2*log(abs(x + 1)) - 1/2*log(abs(x - 1)) + log(abs(x)) == c + t
eq_sub = eq.subs({x: 1/2, t: 0})
show(eq_sub)

12log(32)+12log(12)=c\displaystyle -\frac{1}{2} \, \log\left(\frac{3}{2}\right) + \frac{1}{2} \, \log\left(\frac{1}{2}\right) = c

c_val = solve(eq_sub, c)[0].rhs()
eq_c = eq.subs({c: c_val}) show(eq_c)

12log(x+1)12log(x1)+log(x)=t12log(2)12log(32)\displaystyle -\frac{1}{2} \, \log\left({\left| x + 1 \right|}\right) - \frac{1}{2} \, \log\left({\left| x - 1 \right|}\right) + \log\left({\left| x \right|}\right) = t - \frac{1}{2} \, \log\left(2\right) - \frac{1}{2} \, \log\left(\frac{3}{2}\right)