Solve ode23s in a for loop

1 次查看(过去 30 天)
WANYI ZHANG
WANYI ZHANG 2020-5-19
I want to solve ode23s in a for loop, it solves eventually.
But takes very long time to solve it, can anyone tell me how can I reduce the
time to solve it. The main reason I am using this for loop is that my two of "CS_state"
is changing variables, and my dm_down is also dependent "CS_state"
Below is the code.
Thank you
%%
clc
clear
close all
%% Define global variable(Temperature in Kelvin)
global Kel
Kel = 273.15;
%% Include directories
addpath('ThermalFuncs');
addpath('convectionFuncs');
%% HXsingle_params parameters
condenser_params.H = 138.3627; % Heat transfer coefficient[kWm^-2K^-1]
condenser_params.V = 0.8e-3; % Volume of the heat exhanger [m^3]
expansion_params.A_up = 0.1e-4; % Upstream cross-sectional area of the orifice [m^2]
expansion_params.A_down = 0.0046e-4; % Downstream cross-sectional area of the orifice [m^2]
V = 0.8e-3;
% Create HXsingle_params structure
HX_params.condenser_params=condenser_params;
HX_params.expansion_params=expansion_params;
%% Inputs
T_ext = 35 + Kel;
h_in = 4.571e5;
dm_in = 0.018;
P_out = 0.9e6;
%% Initial condition
Scon=177.1135;
m=0.1178;
CSmacro_state = [Scon;V;m];
v=V/m;
D=1/v;
% s=Scon/m;
CS_state = [Scon;V;m];
% Initial HX_state
x0=[Scon;m];
t=(0:0.01:10);
CS_h_out = zeros(length(t),1);
CS_P_out = zeros(length(t),1);
dm_down = zeros(length(t),1);
for i=1:length(t)
[~,CS_h_out(i),CS_P_out(i),~,~] = CSmacro_output(CS_state,"R410A");
[dm_down(i),~,~] = orifice(CS_h_out(i),CS_P_out(i),P_out,"R410A",expansion_params);
%% Link solver to system equations
ode_wrap = @(t,x) HXmacro_deriv(x,h_in,dm_in,dm_down(i),T_ext,"R410A",HX_params);
% run simulation
opts=odeset('RelTol',1e-6);
[t,x] = ode23s(ode_wrap,t,x0,opts);
CS_state = [x(i,1);V;x(i,2)];
% x0=x;
  3 个评论
WANYI ZHANG
WANYI ZHANG 2020-5-20
These are just creating an empty array of length(t) row,and 1 colume.
I think this is correct.
WANYI ZHANG
WANYI ZHANG 2020-5-20
And they are returning values, as my "CSmacro_output" function take varible CS_state, and whick
returns outputs CS_h_out and CS_P_out.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by