matlab error! "must return a column vector."
2 次查看(过去 30 天)
显示 更早的评论
Hi All,
I am trying to calculate different voltage losses over time. Therefore I wrote such an simple m. file but it does not work and gives "must return a column vector." error
My loss function is:
function n_loss = FC_losses(t,i)
n_loss = zeros(3,1);
para
n_loss(:,1) = i*(l/(sig*area_fc)) + i*R_elec ;
k = (R*T)/(n*F);
n_loss(:,2) = k*log(iL/(iL - i/area_fc));
n_loss(:,3) = 2.3*(R*T)/(alpha_fc*n*F) ;
end
and my ode file is:
clear all
clc
para
i=(0:1:301);
x0 = [0 0 0];
t0 = 0;
tf = 35;
[t,y] = ode23s(@FC_losses,[t0 tf], x0);
y;
t;
plot(t,y(:,1),t,y(:,2),t,y(:,3));
EDIT [28 Jul 2012, 13:53 BST - OK] Moved comment here.
Hi thank you for the help; ok now I will make it more clear:
My "para" m.file which includes diferent variables used in my function
parameters m.file "Para" is:
%common loss parameters
area_fc = 375; % active surface area (cm2)
R = 8.314; % universal gas constant (J/molK)
T = 353; % stack temperature (K)
alpha_fc = 0.5; % transfer coefficient (-)
n = 2; % number of electrons per mole of hydrogen (-)
F = 96487; % faraday constant (C/mole)
%specific ohmic loss parameters
l = 0.0175; % thicknes of the membrane (cm)
sig = 0.1; % intrinsic resistance (ohm x cm)^-1
R_elec = 1e-4; % electrical loss (ohm)
%specific concentration loss parameters
iL = 301/area_fc; % limiting current density (A/cm2)
%specific activation loss paramters
i0 = 0.01; % exchange current density (A/cm2)
and my "FC_losses" function is:
function n_loss = FC_losses(t,i_stack)
n_loss = zeros(3,1); % losses cloumn vector
%load parameters
para
%ohmic voltage loss
n_loss(:,1) = i_stack.*(l/(sig*area_fc)) + i_stack.*R_elec ;
%concentration loss
k = (R*T)/(n*F);
n_loss(:,2) = k*log(iL/(iL - i_stack./area_fc));
%activation loss
n_loss(:,3) = 2.3*(R*T)/(alpha_fc*n*F);
end
Lastly "FC_stack" m.file where ode solver is
% load parameters
para
%current change of the fuel cell
i_stack=(0:50:300);
%initial conditions
x0 = [0 0 0];
%time range of the simulation
t0 = 0;
tf = 35;
[t,y] = ode23s(@FC_losses,[t0 tf], x0);
%plot of the losses;
y;
t;
plot(t,y(:,1),t,y(:,2),t,y(:,3));
end
I hope now it is more clear. my aim here is ploting out voltage losses which are (n_loss(1), n_loss(2), n_loss(3)) over time.
thanks in advance
2 个评论
Elizabeth
2012-7-28
This has got my panties all up in a bunch haha. I don't know much about fuel cells ..But the problem is that when we call @FC_losses, I believe we've assigned n_losses as a matrix comprised of the ohmic voltage loss in one column, the concentration loss in another, and the activation loss vector in the last. Do you have to solve them vectorized like that, or do u think we could use a loop where we solve the ode for each loss vector individually. That way, it'd be easier to get the right dimensions on all our vectors in the problem so that our ode23s solver will work appropriately.. I dont know if that abides by the laws governing the losses of the fuel cell though? So yeah.. I'm not done with this.. Any ideas on your end?
Also, when you say n_loss(1), etc. at the bottom of ur last comment, u do mean n_loss(:,1),etc. right? More so, the : should be the same length as the i_stack vector, correct? Finally, what does x0 signfiy here..?
PS. Sorry if I'm acting like a waste of time. If you got it, or lost hope in my abilities, just tell me so haha.
回答(2 个)
Wayne King
2012-7-28
编辑:Wayne King
2012-7-28
You don't help us to help you when you post a function that will not run like the one you have posted:
function n_loss = FC_losses(t,i)
n_loss = zeros(3,1);
para
n_loss(:,1) = i*(l/(sig*area_fc)) + i*R_elec ;
k = (R*T)/(n*F); n_loss(:,2) = k*log(iL/(iL - i/area_fc));
n_loss(:,3) = 2.3*(R*T)/(alpha_fc*n*F) ;
end
First of all, what is para? Then you have no way of calculating l, or sig, or iL, or many other variables in your function.
3 个评论
Oleg Komarov
2012-7-28
编辑:Oleg Komarov
2012-7-28
@alp: your comment is now embedded into the body of the question.
@Wayne: please refer to the question for additional details.
Elizabeth
2012-7-28
First of all, you initialize n_loss as a 3x1 column vector of zeros and then start to define it as a 3x3 matrix when you use the index n_loss(:,1:3). Second, if i is a vector you are going to need to use .* and ./ in the function. This problem seems to be ill-defined for us to help you. Perhaps if you add more details to numeric values and such it would be easier to follow your code.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle & Nuclear Physics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!