Inputing a function into another function: left and right sides have different elements

10 vues (au cours des 30 derniers jours)
I am quite new to matlab, so hopefully someone can spot my errors!
I have a water function that depends on pressure. The pressure is given a function that changes with time (called Pressure_function). The coefficients are stored in an array called c. This is the pressure function:
function p = Pressure_function(t,c)
p = c(:,1)*t.^8 + c(:,2)*t.^7 + c(:,3)*t.^6 + c(:,4)*t.^5 + c(:,5)*t.^4 + c(:,6)*t.^3 + c(:,7)*t.^2 + c(:,8)*t + c(:,9);
p = p*10^5; %convert to [Pa]
end
Now, I have the water function (which is based off a CSTR in series model at steady state). When the pressure is constant, the function works perfectly. However, I want to make this function transient by inputting the pressure function, since it changes with time. I thougt this would be relatively straightforward (see below). However, I continue to end up with the error 'left and right side have different elements'. I'm not sure how to fix this, so any help would be appreciated!
function [vw] = Water_ss_func(t, ps)
p = @Pressure_function;
%Preallocate (ps.nr is the number of CSTR in series - stored in my struct)
vw = zeros(1,ps.nr);
vw(1) = ps.fv_in - (ps.k *ps.area * p(t,c))/ps.c_w;
for i = 2:ps.nr
vw(i) = vw(i-1) - (ps.k *ps.area * p(t,c))/ps.c_w;
end
end
  4 commentaires
isabella Anglin
isabella Anglin le 13 Oct 2020
Yes, of course, here are my ps values:
%Create parameter structs
ps = struct;
ps.nr = 44; %number of CSTRs
ps.fv_in = 20 * (10^-3)/3600; %[l/hr] converted to [m3/s]
ps.v_in = 20 * 55.85/3600; %[l/hr] to [mol/s]
ps.k = 0.000005; %inital guess
ps.area = 0.08/ps.nr; %Area of each CSTR for permeation [m2]
ps.p_ext = 2.2864 *10^5; %barg converted to pascal [Pa]
ps.c_bsa_in = 0.0323; %mol/m3 (taken from steady state value of feed
ps.R = 8.314; %J/molK
ps.vol = (0.00083^2 *pi/4 * 102 *0.30)/ps.nr;
ps.T = 298; %K
ps.c_w = 55358; %[mol/m3] of water
ps.nw_in = ps.vol *ps.c_w; %[mol] water
And c is:
c = 3.96579976144065e-16 7.69738447503576e-14 -1.30016421641611e-10 3.89802375870541e-08 -5.57066417121402e-06 0.000438052477869725 -0.0190876028666973 0.412616772886201 -0.564804289797713
And the time input will be t_exp, the experimental time, from 0 to 146.2 s (see attached mat file!)
Thank you in advance for your help :)
Uday Pradhan
Uday Pradhan le 15 Oct 2020
Hi Isabella,
Since t_exp is a 145 x 1 vector, the line:
vw(1) = ps.fv_in - (ps.k *ps.area * p(t,c))/ps.c_w;
is causing an error as the sizes of the two sides are not the same. p(t_exp,c) will also return a 145 x 1 vector and we cannot assign this to vw(1) since it's a scalar. May be you want to evaluate Water_ss_func at each time step? Something like:
Water_ss_func(t_exp(10), ps)

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Chemistry 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!

Translated by