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

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)

Answers (2)

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

thanks for your reply i have used function now and its still not giving any numerical values but values in exponential form
function [A,C]=absent(A0,C0,k,t)
syms A1(t) C1(t) k
ode1=diff(A1,t)==-k*A1;
ode2=diff(C1,t)==k*A1;
odes=[ode1;ode2];
S=dsolve(odes);
Asol(t)=S.A1;
Csol(t)=S.C1;
[Asol(t), Csol(t)]=dsolve(odes);
cond1=A1(0)==A0;
cond2=C1(0)==C0;
conds=[cond1;cond2];
[Asol(t),Csol(t)]=dsolve(odes,conds);
A = vpa(Asol(t))
C = vpa(Csol(t))
end
the output is
A =
5.0*exp(-1.0*k*t)
C =
10.0 - 5.0*exp(-1.0*k*t)
If you want a numeric result, you need to use a numeric argument to the functions.
See my Answer, and Walter Roberson’s extension of it.
Mine is also numeric substitution(t is substituted). After it, ASol and CSol become numeric vectors.
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.
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))

Sign in to comment.

Asked:

on 1 Feb 2018

Commented:

on 1 Feb 2018

Community Treasure Hunt

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

Start Hunting!