MATLAB solve Ordinary Differential Equations -


how can use matlab solve following ordinary differential equations?

x''/y = y''/x = -( x''y + 2x'y' + xy'')

with 2 known points, such t=0: x(0)= x0, y(0) = y0; t=1: x(1) = x1, y(1) = y1 ? doesn't need complete formula if difficult. numerical solution ok, means, given specific t, can value of x(t) , y(t).

if matlab hard this, mathematica ok. not familiar mathematica, prefer matlab if possible.

looking forward help, thanks!

i asked same question on stackexchange, haven't answer yet. https://math.stackexchange.com/questions/812985/matlab-or-mathematica-solve-ordinary-differential-equations

hope can problem solved here!

what have tried is:

---------matlab

syms t

>> [x, y] = dsolve('(d2x)/y = -(y*d2x + 2dx*dy + x*d2y)', '(d2y)/x = -(y*d2x + 2dx*dy + x*d2y)','t')   error using sym>convertexpression (line 2246) conversion 'sym' returned mupad error: error: unexpected 'identifier'. [line 1, col 31]  error in sym>convertchar (line 2157) s = convertexpression(x);  error in sym>convertcharwithoption (line 2140)     s = convertchar(x);  error in sym>tomupad (line 1871)     s = convertcharwithoption(x,a);  error in sym (line 104)         s.s = tomupad(x,'');  error in dsolve>mupaddsolve (line 324) sys = [sys_sym sym(sys_str)];  error in dsolve (line 186) sol = mupaddsolve(args, options); 

--------matlab

also, tried add conditions, such x(0) = 2, y(0)=8, x(1) = 7, y(1) = 18, , errors still similar. think cannot solve dsolve function.

so, again, key problem is, given 2 known points, such when t=0: x(0)= x0, y(0) = y0; t=1: x(1) = x1, y(1) = y1 , how value of x(t) , y(t)?

update: tried ode45 functions. first, in order turn 2-order equations 1-order, set x1 = x, x2=y, x3=x', x4=y'. after calculation, equation becomes:

x(1)' = x(3)                                                (1)  x(2)' = x(4)                                                (2)  x(3)' = x(2)/x(1)*(-2*x(1)*x(3)*x(4)/(1+x(1)^2+x(2)^2))     (3)  x(4)' = -2*x(1)*x(3)*x(4)/(1+x(1)^2+x(2)^2)                 (4) 

so matlab code wrote is:

myodes.m  function xdot = myodes(t,x)  xdot = [x(3); x(4); x(2)/x(1)*(-2*x(1)*x(3)*x(4)/(1+x(1)^2+x(2)^2)); -2*x(1)*x(3)*x(4)/(1+x(1)^2+x(2)^2)]  end  main.m t0 = 0; tf = 1; x0 = [2 3 5 7]'; [t,x] = ode45('myodes',[t0,tf],x0); plot(t,x) 

it can work. however, not right. because, know when t=0, value of x , y, x(1) , x(2); , when t=1, value of x , y. ode functions need initial value: x0, wrote condition x0 = [2 3 5 7]' randomly code work. how solve problem?

update: tried use function bvp4c after realized boundary value problem , following code (suppose 2 boundry value conditions are: when t=0: x=1, y=3; when t=1, x=6, y=9. x x(1), y x(2) ):

1. bc.m function res = bc(ya,yb) res = [ ya(1)-1; ya(2)-3; yb(1) - 6; yb(2)-9]; end 2. ode.m function dydx = ode(t,x) dydx = [x(3); x(4); x(2)/x(1)*(-2*x(1)*x(3)*x(4)/(1+x(1)^2+x(2)^2)); -2*x(1)*x(3)*x(4)/(1+x(1)^2+x(2)^2)]; end 3. mainbvp.m solinit = bvpinit(linspace(0,6,10),[1 0 -1 0]); sol = bvp4c(@ode,@bc,solinit); t = linspace(0,6); x = deval(sol,t); plot(t,x(1,:)); hold on plot(t,x(2,:));  plot(t,x(3,:));  plot(t,x(4,:)); x(1,:) x(2,:) 

it can work, don't know whether right. check again make sure right code.

as mentioned, isn't math site, try give code or showing effort. however, first step need turn de normal form (i.e., no 2nd derivatives). making separate variable equal derivative. then, use

syms x y % or variable instead of x or y 

to define variables symbolic. use matlabfunction create symbolic function based on these variables. finally, can use ode45 function solve symbolic function while passing variable values. recommend full documentation in matlab in order understand better, here basic syntax:

myfun= matlabfunction(eq,'vars',{x,y}); [xout,yout]=ode45(@(x,y) myfun(variables),[variable values],options); 

hopefully puts in right direction, try messing around , provide code if need more help.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -