Hi i have made a separable differential equation now i want to put values of t at instant, equations are made but i down know how to put value
1 view (last 30 days)
Show older comments
syms A(t) C(t) k
k=4;
ode1=diff(A,t)==-k*A
ode2=diff(C,t)==k*A
odes=[ode1;ode2]
S=dsolve(odes)
Asol(t)=S.A
Csol(t)=S.C
[Asol(t), Csol(t)]=dsolve(odes)
cond1=A(0)==5
cond2=C(0)==5
conds=[cond1;cond2]
[Asol(t),Csol(t)]=dsolve(odes,conds)
0 Comments
Answers (2)
Star Strider
on 1 Feb 2018
When you run your code, you create ‘Asol’ and ‘Csol’ as functions. So you only need to give them numeric arguments (here 3 arbitrarily) to get the result:
Result_1 = vpa(Asol(3))
Result_2 = vpa(Csol(3))
Result_1 =
0.000030721061766641048793411540894028
Result_2 =
9.9999692789382333589512065884591
7 Comments
Star Strider
on 1 Feb 2018
My code takes advantage of the original code creating functions, so you only need to deal with them as straightforward functions. It is much simpler and more efficient.
Walter Roberson
on 1 Feb 2018
vpa() and subs() and calling the symbolic function with numeric values will all produce symbolic results. Those symbolic results can increasingly be used in place of numeric results, but not in all contexts.
To get a numeric result, apply double() to the symbolic result. Like double(Asol(1.234))
Walter Roberson
on 1 Feb 2018
For example:
t_values = linspace(0, 10, 100);
plot(t_values, Asol(t_values))
0 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!