How to assign values to the variables using "dsolve" for solving first order ODE Equations simultaneously ?

3 vues (au cours des 30 derniers jours)
I am using "dsolve" to solve my first order ode .The function "dsolve" works fine but it does not allow assigning values to the variables. My code is given as follows.
%Parameters clear all; syms A Epsilon0 k1 k2 e s d R s f T c0 ; A=0.5*10^(-9); Epsilon0=8.85*10^-12; k1=10; k2=10; e=1.6*10^-19; s = 1.8*10^(-9);%m gap size% d=3*s; % total distance R=1; t=0:(0.0001*10^-3):(0.5*10^-3); f=10000; v0=7.5; T=5/f; v=v0*sin(2*pi*f*t); plot(t,v); c0=(A*Epsilon0*k1)/d;
inits='q(0)=(20*10^(-20)),Q(0)=0'; [q,Q]=dsolve('Dq=((v/R)-(1/R)*(((d*q)+(s*Q))/(c0*d)))','DQ=(((q+Q)/(A*Epsilon0*k1))*s)',inits);
OUTPUT q =
(c0*d*exp((s*t)/(2*A*Epsilon0*k1)............................................(this is so long expression).
Issue: In the above out, the variables are used instead of the values i have assigned and initialized in the code .
Requirement : I need these variables to be replaced by the values i have assigned to them.

Réponse acceptée

Mischa Kim
Mischa Kim le 20 Avr 2015
AK, use the subs command. I also recommend differentiating between the symbolic variables and their numeric values, e.g. A versus An .
syms A Epsilon0 k1 k2 e s d R s f T c0
An = 0.5*10^(-9);
Epsilon0n = 8.85*10^-12;
k1n = 10;
k2n = 10;
en = 1.6*10^-19;
sn = 1.8*10^(-9);%m gap size%
dn = 3*s; % total distance
Rn = 1;
inits = 'q(0)=(20*10^(-20)),Q(0)=0';
[q,Q] = dsolve('Dq=((v/R)-(1/R)*(((d*q)+(s*Q))/(c0*d)))','DQ=(((q+Q)/(A*Epsilon0*k1))*s)',inits);
qn = vpa(subs(q,{A,Epsilon0,k1,k2,e,s,d,R},{An,Epsilon0n,k1n,k2n,en,sn,dn,Rn}),3);
  1 commentaire
AK Khan
AK Khan le 20 Avr 2015
Modifié(e) : AK Khan le 20 Avr 2015
Thanks for the answer. I want to plot this function vs time. For that , i replaced v with vn while vn is the input sinusoidal source. Now the problem is that it takes so much time to execute and the out exprssion exceeds the command line showing capability.I EDITED the code like this below.Only change is the last line .i.e vactorize just for plotting and incoparated the input voltage as vn by your suggested sub method.
if true
% syms A Epsilon0 k1 k2 e s d R s f T c0 v0 v
An = 0.5*10^(-9);
Epsilon0n = 8.85*10^-12;
k1n = 10;
k2n = 10;
en = 1.6*10^-19;
sn = 1.8*10^(-9);%m gap size%
dn = 3*sn; % total distance
Rn = 1;
c0n=(An*Epsilon0n*k1n)/dn;
t=0:(0.0001*10^-3):(0.5*10^-3); fn=10000; v0n=7.5; Tn=5/f; vn=v0n*sin(2*3.14*fn*t);
inits = 'q(0)=(20*10^(-20)),Q(0)=0'; [q,Q] = dsolve('Dq=((v/R)-(1/R)*(((d*q)+(s*Q))/(c0*d)))','DQ=(((q+Q)/(A*Epsilon0*k1))*s)',inits); qn = vpa(subs(q,{A,Epsilon0,k1,k2,e,s,d,R,c0,v},{An,Epsilon0n,k1n,k2n,en,sn,dn,Rn,c0n,vn}),8); qq=eval(vectorize(qn));
end
I will really appreciate your kind suggestion in this regard.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by