Need to rectify error in my matlab code given below
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
syms t
mu=2500*(10^-4); %cm^2*V^-1 * s^-1
R = 0.318;
eta=377;% ohm
N=3.681; %refindex
Pavg=7;%W
Za=50;%ohm
g=100*(10^-6);%m
pi=3.14;
alpha= 8.5*(10^4); %m^-1
taul= 35*(10^-15); %s
tauc= 10*(10^-12); %s
W=100*(10^-6); %m
L=300*(10^-6); % m
Tlt=325*(10^-6); % m
V=25; %V
E=V./g;
vopt=375*(10^12); %Hz
e=1.602*(10^-19);
h=6.626*(10^-34);
I=0.90*(10^8);% i
t=linspace(-0.5*(10^-12),3.0*(10^-12),100);
n(t)=I.*exp(-2).*((1-R)./(sqrt(2.*pi).*h.*vopt)).*taul.*exp((-taul.^2)./(8.*tauc.^2)).*exp(-t./tauc).*(erf(sqrt(2).*t./taul - (sqrt(2).*taul)./(4.*tauc))+1);
tc = 10.*(10.^-12);
n0=10.^18
dt=80.*(10^-12);
G=n0.*exp((-t.*t)/(dt.*dt))
ode = diff(n,t) == (-n./tc) + G;
cond = n(0) == n0;
nSol(t)=dsolve(ode,cond);
It shows difference order N must be a positive integer. Error in third last line. How to solve this error?
2 commentaires
Torsten
le 1 Oct 2024
I don't understand what you want to do with your code.
If you define n(t) as a function of t, diff(n,t) == (-n/tx) + G is not a differential equation, but an algebraic relation. Thus using "dsolve" on it makes no sense.
Réponses (2)
Hitesh
le 1 Oct 2024
Hi Jasmine,
The error you encounter is due to the incorrect use of symbolic differentiation and the definition of “n(t)” as a symbolic function. You can fix this by ensuring that “n(t)” is defined correctly as a symbolic function and that the differentiation is performed on a symbolic expression.
Here are key modifications that are required in your code:
- Declare “n(t)” as a symbolic function using “syms n(t)”.
- Define “n_expr” as a symbolic expression for “n(t)”.
- Use “subs” to evaluate “nSol” over the range “t_vals”.
- Correct the use of “pi” by defining “pi_val” to avoid conflict with MATLAB's built-in “pi”.
syms t n(t) % Declare n as a symbolic function of t
E = V / g;
t_vals = linspace(-0.5 * (10^-12), 3.0 * (10^-12), 100);
% Define the expression for n(t)
n_expr = I * exp(-2) * ((1 - R) / (sqrt(2 * pi_val) * h * vopt)) * taul * ...
exp((-taul^2) / (8 * tauc^2)) * exp(-t / tauc) * ...
(erf(sqrt(2) * t / taul - (sqrt(2) * taul) / (4 * tauc)) + 1);
tc = 10 * (10^-12);
n0 = 10^18;
dt = 80 * (10^-12);
% Define G(t)
G_expr = n0 * exp((-t * t) / (dt * dt));
% Define the differential equation
ode = diff(n, t) == (-n / tc) + G_expr;
% Evaluate the solution over the specified range
nSol_vals = double(subs(nSol, t, t_vals))
0 commentaires
Torsten
le 1 Oct 2024
Modifié(e) : Torsten
le 1 Oct 2024
I want to get a plot of dn/dt versus t.
syms t
mu=2500*(10^-4); %cm^2*V^-1 * s^-1
R = 0.318;
eta=377;% ohm
N=3.681; %refindex
Pavg=7;%W
Za=50;%ohm
g=100*(10^-6);%m
pi=3.14;
alpha= 8.5*(10^4); %m^-1
taul= 35*(10^-15); %s
tauc= 10*(10^-12); %s
W=100*(10^-6); %m
L=300*(10^-6); % m
Tlt=325*(10^-6); % m
V=25; %V
E=V./g;
vopt=375*(10^12); %Hz
e=1.602*(10^-19);
h=6.626*(10^-34);
I=0.90*(10^8);% i
n=I.*exp(-2).*((1-R)./(sqrt(2.*pi).*h.*vopt)).*taul.*exp((-taul.^2)./(8.*tauc.^2)).*exp(-t./tauc).*(erf(sqrt(2).*t./taul - (sqrt(2).*taul)./(4.*tauc))+1);
dn = diff(n,t);
tnum=linspace(-0.5*(10^-12),3.0*(10^-12),100);
dnnum = subs(dn,t,tnum);
plot(tnum,dnnum)
3 commentaires
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!