matlab error! "must return a column vector."

2 vues (au cours des 30 derniers jours)
alp
alp le 28 Juil 2012
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 commentaires
Elizabeth
Elizabeth le 28 Juil 2012
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.
alp
alp le 28 Juil 2012
thank you for your interest on my question, I appreciate that! First of all, to be honest even I am not clear on this work. However it is clear that there is no diferential equations in my ODE and these three loss equations are composed of some parameters. therefore you do not need to know too much about fuel cells.
I am wondering If I can get a plotout of these three losses which change over time, namely (t,n_loss(1),t,n_loss(2),t,n_loss(3)). I know my input current which is i_stack, should be an array, and changes over time, so the losses. But I could not achieve that.
About your questions begining from the last: x0 is array form of my initial value of my losses wich are defined [0 0 0]. you are right 3 losses have to have same length as i_stack which I could not do :(
I have done this with simulink where I am able get individual loss change over time. I am not sure wether I am allowed to solve this with ODE23s, same as in simulink.
But your matrix and loop approach seems quite logical. The way of solving is not so important. the only important thing, I have to solve this in m.file and want to see individual loss changes over time. Again there is no differential equation in FC_losses function as you see they are just simple parameter interaction.
I hope it is more clear to you now and please do not think like that I just want to learn s.thing more to achive this.

Connectez-vous pour commenter.

Réponses (2)

Wayne King
Wayne King le 28 Juil 2012
Modifié(e) : Wayne King le 28 Juil 2012
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 commentaires
Wayne King
Wayne King le 28 Juil 2012
then how are we supposed to debug your problem?
Oleg Komarov
Oleg Komarov le 28 Juil 2012
Modifié(e) : Oleg Komarov le 28 Juil 2012
@alp: your comment is now embedded into the body of the question.
@Wayne: please refer to the question for additional details.

Connectez-vous pour commenter.


Elizabeth
Elizabeth le 28 Juil 2012
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.
  1 commentaire
Oleg Komarov
Oleg Komarov le 28 Juil 2012
@alp: I moved your comment into the body of your question.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Particle & Nuclear Physics 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