0
|
9738 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
GROUPS:

# Substituting values into a DSolve solution of ODE

Posted 10 years ago
 Hi, I'm trying to subsitute values to a rule, which I obtain as a solution to a ode.sol = DSolve[V''[x] + V[x]/(L C) ==  Es/(L C), V[x], x] Now the goal is to convert the answer into following format I tried to use /. command as follow , but not success.% /. Sqrt[L]  Sqrt[C]  -> wPls give me a certain direction on this.
4 Replies
Sort By:
Posted 10 years ago
 Thanks. Most importantly for tipping for mathematically deriving it rather than subsituting variables.I used system of ode's with initial conditions. Hence the solution already cater for the initial states.(of capacitor and inductor)Revised code  In:= eqn = {iL'[t] + 1/L Vc[t] == Es/L, Vc'[t] == 1/c  iL[t],  Vc == Vc0 , iL == iL0}  Out= {Vc[t]/L + Derivative[iL][t] == Es/L, Derivative[Vc][t] == iL[t]/c, Vc == Vc0, iL == iL0}  In:= sol2 = Vc[t] /. DSolve[eqn, {Vc[t], iL[t]}, t][[1, 2]] //  FullSimplify  (* Capacitor Voltage *)  Out= Es + (-Es + Vc0) Cos[t/(Sqrt[c] Sqrt[L])] + (iL0 Sqrt[L] Sin[t/(Sqrt[c] Sqrt[L])])/Sqrt[c]  In:= sol2 =  sol2 /. Power[c_, Rational[-1, 2]]*Power[L_, Rational[-1, 2]]*t ->  w *t   (* 1/Sqrt[LC] \[Rule] w *)Out= Es + (-Es + Vc0) Cos[t w] + (iL0 Sqrt[L] Sin[t w])/Sqrt[c]In:= sol1 = iL[t] /. DSolve[eqn, {Vc[t], iL[t]}, t][[1, 1]] // FullSimplify  (*  inductor current *)Out= iL0 Cos[t/(Sqrt[c] Sqrt[L])] + ( Sqrt[c] (Es - Vc0) Sin[t/(Sqrt[c] Sqrt[L])])/Sqrt[L]In:= sol1 =  sol1 /. Power[c_, Rational[-1, 2]]*Power[L_, Rational[-1, 2]]*t ->   w *t   (* 1/Sqrt[LC] \[Rule] w *)Out= iL0 Cos[t w] + (Sqrt[c] (Es - Vc0) Sin[t w])/Sqrt[L]In:= sol2a =  sol2 /. a_*Sin[q_] + b_*Cos[q_] ->    Sqrt[a^2 + b^2]*Sin[q + ArcTan[b/a]] (*  Trignomertry Linear Combination *)Out= Es +  Sqrt[(iL0^2 L)/c + (-Es + Vc0)^2] Sin[t w + ArcTan[(Sqrt[c] (-Es + Vc0))/(iL0 Sqrt[L])]]Agree. Its much simpler to fix minor adjustment for display using the word processor
Posted 10 years ago
 I am glad you were able to see how to use the example to accomplish your goal. That is what I hoped you would be able to do.You can always try to force Mathematica to do things and display things the way you want and not the way Mathematica wants. But you should probably be warned that this may be more and more difficult and time consuming the harder you try to fight against what Mathematica wants to do. Again and again you can find examples where people want the output to be "desktop published" or to look like what is in their textbook. This often leads to difficulties and errors and people begging to be told why what they have tried to do is not working. But some people just must do that.Try this.In:= Sin[t w] /. t w -> HoldForm[w t]Out= Sin[w t]In:= FullForm[%]Out//FullForm= Sin[HoldForm[w t]]]] This may display they way you want, but you will then find you cannot do anything else with it until you undo what you have just asked for.You may find it easier to read the result, in the wrong order, and then go type it into your desktop publishing system in the order that you desire and publish that.If you need to do too much pattern matching for replacement then this might be a hint to use your desktop publishing system or word processor instead. Pattern matching and replacement have no understanding of mathematics at all and will just as easily let you make an incorrect replacement as a correct replacement. If you give DSolve the correct initial conditions for your differential equation then it does have some understanding of mathematics and should not do incorrect substitutions or give incorrect results. Then at the last step you can desktop publish the result into the style that you wish.
Posted 10 years ago
 Thanks for the informative response.I further tweaked the code to obtain the desired answer In:= sol =  V[t] /. DSolve[{V''[t] + V[t]/(L c) == Es/(L c)}, V[t], t][]  Out= Es + C Cos[t/(Sqrt[c] Sqrt[L])] +  C Sin[t/(Sqrt[c] Sqrt[L])]  In:=  sol = sol /.  Power[c_, Rational[-1, 2]]*Power[L_, Rational[-1, 2]]*t -> w *t   (* 1/Sqrt[LC] \[Rule] w *)  Out= Es + C Cos[t w] + C Sin[t w]  In:= sol2 = sol /. a_*Sin[q_] + b_*Cos[q_] ->  Sqrt[a^2 + b^2]*Sin[q + ArcTan[b/a]] (*  Trignomertry Linear Combination *)Out= Es + Sqrt[C^2 + C^2] Sin[t w + ArcTan[C/C]]In:= sol3 = sol2 /. {Sqrt[C^2 + C^2] -> Xs, (C/C) -> \[Phi]} (* where C=(Vcio -Es) and C=(Ilio/(wc)) *)Out= Es + Xs Sin[t w + ArcTan[\[Phi]]] (* is it possible to list Sin (w t) instead of Sin (t w) *)One minor question is it possible to change the order of variable display formatie i'd like to have the output as Sin(w t) instead of Sin (t w)  . Its seems like mathematica automatically rearrange them alphabetically.
Posted 10 years ago
 Substitutions, particularly for powers, radicals and denominators, have always been "somewhat challenging."See if this will help. This x/(Sqrt[c]Sqrt[L])/.Sqrt[L]Sqrt[c]->1/w will not substitute while this x/(Sqrt[c]Sqrt[L])/. 1/Sqrt[L]*1/Sqrt[c]->1/w will correctly substitute. Or try this  In:= sol = V[x] /. DSolve[V''[x] + V[x]/(L c) == Es/(L c), V[x], x][]Out= Es + C Cos[x/(Sqrt[c] Sqrt[L])] + C Sin[x/(Sqrt[c] Sqrt[L])]In:= sol = sol/.x*Power[c_,Rational[-1,2]]*Power[L_,Rational[-1,2]]->x/wOut= Es + C Cos[x/w] + C Sin[x/w]Now use http://en.wikipedia.org/wiki/List_of _trigonometric _identities#Linear_combinationsIn:= sol = sol /. a_*Sin[q_] + b_*Cos[q_] -> Sqrt[a^2 + b^2] Sin[q + ArcSin[b/Sqrt[a^2 + b^2]]]Out= Es + Sqrt[C^2 + C^2] Sin[x/w + ArcSin[C/Sqrt[C^2 + C^2]]]Note that I have used c instead of C because C has a defined meaning to Mathematica and that isn't the size of a capacitor.When you can't get a replacement pattern to work the advice is always to use FullForm to see what the internal Mathematica form is for the expression and then use that literally in your replacement pattern.  Sometimes you can use something less detailed than that and still have it work, but that is always a good first step to try. Also be very careful to include a space between /. and 1 if you do anything like expr/. 1/w so that it does not interpret .1 as decimal one-tenth.Also watch out for the domain information given on that wiki page for the trig substitution to make sure that I haven't chosen the wrong replacement. If there were a single Mathematica command that would do that subsitution and automatically take into account the signs that would be great, but I am not aware of something that will do that.If you can give some initial conditions to DSolve then it may automatically replace C and C with the appropriate values.Note to staff. It would be really really really nice if v would correctly paste inside a code box someday. v woks fine for an initial paste into a code box, but any subsequent attempt to highlight part of that box and paste a replacement doesn't paste. Being able to make simple edits like that would be very helpful and far less error prone than just "typing it all back in again." Thank you.