ODE 45 couldn't solve the differential equation.

2 次查看(过去 30 天)
I have a differential equation of pump power of eerbium wave guide. The ODE should be solved in matlab. I dont know how to use ODE properly. I have solved only simple ODE in matlab.if you can check it. please.
This is my code.
clc
clear
close all
L=10;
z=0:0.1:L;
Nt = [1.2*10^(20), 1.2*10^(20), 1.2*10^(20)];
ap=0.23e2;
sca=2.1e-25;
Tp=0.85;
Tcb = 30*10^(-6);
Tba = 2.3*10^(-3);
vs=196e12;
vp=307e12;
h=6.625*10^(-34);
Pp0=10^(-3);
Ps0=10^(-6);
sab=4.8e-2;
sac=2.1e-21;
sba=4.4e-21;
Is=Ps0*exp(-ap)/(2*pi*0.8e-8);
Ip=Pp0*exp(-ap*z)/(2*pi*0.8e-8);
Wab=Is*sab/h*vs;
Wac=Ip*sac/h*vp;
Wba=Is*sba/h*vs;
nb=((Wab+Wac)/1+Wac*Tcb)/(Wab+Wba+(1/Tba)+(Wac*(1-Wab*Tcb)/(1+Wac*Tcb)));
nc=(Wac*Tcb*(1-nb)')./(1+Wac*Tcb);
na=1-nb-nc;
for k = 1:3
ode_ = @(z,Pp) (-ap + (((sca*nc)-(sac*na))*Tp*Nt(k)*Pp))';
PSol(z) = ode45(ode_, [0 L], 0);
Pp_sol(k) = PSol;
end
I need the solution of Pp in three different Nt valus. that is why I have given a for loop. this gives me an error.
% Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
%
% Error in ode (line 42)
% Pp_sol(k) = PSol;
The z values can't be given as an array. Then it gave me another error,
% Error using odearguments (line 95)
% @(Z,PP)(-AP+(((SCA*NC)-(SAC*NA))*TP*NT(K)*PP))' returns a vector of length 101, but the length of initial conditions
% vector is 1. The vector returned by @(Z,PP)(-AP+(((SCA*NC)-(SAC*NA))*TP*NT(K)*PP))' and the initial conditions vector
% must have the same number of elements.
%
% Error in ode45 (line 115)
% odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
%
% Error in ode (line 41)
% PSol(z) = ode45(ode_, [0 L], 0);
I have given it as a random alue to check if the loop is working.

回答(1 个)

darova
darova 2021-8-9
Try this way
psol = [];
for k = 1:3
ode_ = @(z,Pp) (-ap + (((sca*nc)-(sac*na))*Tp*Nt(k)*Pp))';
psol = [psol; ode45(ode_, [0 L], 0)];
end

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by