Solve ode23s in a for loop

6 Ansichten (letzte 30 Tage)
WANYI ZHANG
WANYI ZHANG am 19 Mai 2020
Kommentiert: WANYI ZHANG am 20 Mai 2020
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 Kommentare
WANYI ZHANG
WANYI ZHANG am 20 Mai 2020
These are just creating an empty array of length(t) row,and 1 colume.
I think this is correct.
WANYI ZHANG
WANYI ZHANG am 20 Mai 2020
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by