ODE 45 couldn't solve the differential equation.

1 回表示 (過去 30 日間)
Abhiram CD
Abhiram CD 2021 年 8 月 8 日
回答済み: darova 2021 年 8 月 9 日
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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by