Trouble using dsolve function

7 views (last 30 days)
Nitin
Nitin on 20 Jan 2012
Hi,
I need help in solving a 2nd order diff equations. Since my equations are very long (almost 30 lines), I have written a similar code below to explain my question.
z= a*x+b*x^2+c+........; S =dsolve('D2y +5*z+ 2*x + 10*z^2','x')
Now since my z equation is very long I need to substitute z in the dsolve function. I tried using inline function by doing this
z = inline ('a*x+b*x^2+c+........')
but I am not sure if the dsolve program is taking the value of z. Its running though, and it says no explicit solution found and returns me an empty symbol. Am I doing the right thing or is there any other way to do it.

Accepted Answer

Walter Roberson
Walter Roberson on 20 Jan 2012
z = a*x+b*x^2+c+........;
eqn = subs(sym('D2y +5*z+ 2*x + 10*z^2'), z, z);
S = dsolve(eqn, x);
Myself, I would probably toss in a simplify() around the subs() .
  2 Comments
Nitin
Nitin on 20 Jan 2012
Hey Walter,
Thank you for your reply. I tried you subs and simplify function like this for my equation
eqn1 = simplify(subs(sym('(D2p1/((8.314)*(573.15)))+(((((p1+p2+p3)*Dp2-(Dp1+Dp2+Dp3))/(p1+p2+p3)^2)*N1+(p2/(p1+p2+p3))*(-N1/r)-N2*(((p1+p2+p3)*Dp1-(Dp1+Dp2+Dp3))/(p1+p2+p3)^2)-(p1/(p1+p2+p3))*(-N2/r))/(1.7241e-05)+((((p1+p2+p3)*Dp3-(Dp1+Dp2+Dp3))/(p1+p2+p3)^2)*N1+(-N1/r)*(p3/(p1+p2+p3))-(p1/(p1+p2+p3))*(-k*p1/(R*T)-N3/r)-N3*(((p1+p2+p3)*Dp1-(Dp1+Dp2+Dp3))/(p1+p2+p3)^2))/(1.0642e-05))+(-N1/r)/(5.6164e-08)+((9.5703e-18)/((8.314)*(573.15)*(0.00001027)*(5.6164e-08))*((((p1+p2+p3)*Dp1-(Dp1+Dp2+Dp3))/(p1+p2+p3)^2)*(p1+p2+p3)*(Dp1+Dp2+Dp3)+(p1/(p1+p2+p3))*(Dp1+Dp2+Dp3)*(p1+p2+p3)+(p1/(p1+p2+p3))*((Dp1+Dp2+Dp3))^2))'), N1, N1, N2, N2, N1, N1, N3, N3, N1));
But I get an error
??? Error using ==> sym.subs
Too many input arguments.
Can you show me the right syntax for this.
Thanks once again.
Walter Roberson
Walter Roberson on 20 Jan 2012
The syntax I used is valid for the case of exactly one thing to substitute in. When you have multiple things to substitute in, you must form lists.
eq1 = simplify(subs(...., {'N1', 'N2', 'N3'}, {N1, N2, N3}))

Sign in to comment.

More Answers (2)

Nitin
Nitin on 20 Jan 2012
Hey Walter,
I fixed the problem. Many thanks for your help. Can you tell me one more thing. After I run my program, it gives me this message Warning: Empty equation In dsolve at 91 In secondorder at 92
can you tell me what this means. I searched on the matlab website and there is no such warnings listed.
thanks, Nitin

Nitin
Nitin on 20 Jan 2012
Hey Walter,
This is my code
eqn1 = simplify(subs(sym('(D2p1/((8.314)*(573.15)))+(((((p1+p2+p3)*Dp2-(Dp1+Dp2+Dp3))/(p1+p2+p3)^2)*N1+(p2/(p1+p2+p3))*(-N1/r)-N2*(((p1+p2+p3)*Dp1-(Dp1+Dp2+Dp3))/(p1+p2+p3)^2)-(p1/(p1+p2+p3))*(-N2/r))/(1.7241e-05)+((((p1+p2+p3)*Dp3-(Dp1+Dp2+Dp3))/(p1+p2+p3)^2)*N1+(-N1/r)*(p3/(p1+p2+p3))-(p1/(p1+p2+p3))*(-k*p1/(R*T)-N3/r)-N3*(((p1+p2+p3)*Dp1-(Dp1+Dp2+Dp3))/(p1+p2+p3)^2))/(1.0642e-05))+(-N1/r)/(5.6164e-08)+((9.5703e-18)/((8.314)*(573.15)*(0.00001027)*(5.6164e-08))*((((p1+p2+p3)*Dp1-(Dp1+Dp2+Dp3))/(p1+p2+p3)^2)*(p1+p2+p3)*(Dp1+Dp2+Dp3)+(p1/(p1+p2+p3))*(Dp1+Dp2+Dp3)*(p1+p2+p3)+(p1/(p1+p2+p3))*((Dp1+Dp2+Dp3))^2))'), {N1 N1 N2 N2 N1 N1 N3 N3 N1}, {N1 N1 N2 N2 N1 N1 N3 N3 N1}));
eqn2 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.9194e-08)+((9.5703e-18)/((8.314)*(573.15)*(0.00001027)*(1.9194e-08))*((((p1+p2+p3)*Dp3-(Dp1+Dp2+Dp3))/(p1+p2+p3)^2)*(p1+p2+p3)*(Dp1+Dp2+Dp3)+(p3/(p1+p2+p3))*(Dp1+Dp2+Dp3)*(p1+p2+p3)+(p3/(p1+p2+p3))*((Dp1+Dp2+Dp3))^2))'), {N3 N3 N1 N1 N3 N3 N2 N2 N3}, {N3 N3 N1 N1 N3 N3 N2 N2 N3}));
S = dsolve(eqn1, eqn2, eqn3, r)
This on running gives me empty equation warning. I used the subs above like you said to substitute for the values of N1 , N2 and N3. Can you tell me where I am wrong. Does N1, N2 and N3 not substitute in these equations ?
Thanks, Nitin

Categories

Find more on Function Creation in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!