Subscript indices Error for a Plot
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi I am trying to calculate power but I cant seem to find out what is wrong (im a novice in matlab) The error is in the line for P_out.
%%An example of Matlab code
clc;clear;
format long;
%%Constants
hf_H2 = 0;
hf_O2 = 0;
hf_H2Og = -244820;
sf_H2 = 130.68;
sf_O2 = 205.14;
sf_H2Og = 188.72;
cp_H2O = 33.7;
cp_H2 = 29.5;
cp_O2 = 329.0;
Tref = 298;
Ru = 8.314;
T = 353;
n = 2;
F = 96487;
p_H2 = 1;
p_O2 = 0.21;
a_H2O = 1;
po = 1;
delT = T-Tref;
%%Calculate Nerst Reversible Cell Potential
% Calculate Gibbs Free Energy
delH = hf_H2Og+cp_H2O*delT - (hf_H2+cp_H2*delT) - 0.5*(hf_O2+cp_O2*delT);
delS = sf_H2Og+cp_H2O*log(T/Tref) - (sf_H2+cp_H2*log(T/Tref)) - 0.5*(sf_O2+cp_O2*log(T/Tref));
delG = delH - (Tref * delS);
% Reversible voltage
Ero = -delG/(n*F);
% Nerst Expression for voltage
Eo=Ero+(Ru*T/n/F)*log((p_H2/po)*(p_O2/po)^0.5);
%%Populating matrix for calculations
V_mdl = @(a,I)(Eo-Ru*T/F*log((I+a(4))/a(1))+Ru*T/2./F*log((a(2)-(I+a(4)))/a(2))-I*a(3));
I_exp = [0,2.5,5,10,20,40,60,80,100,200,400,600,800,1000,1200];
V_exp = [0.986615,0.950774,0.951704,0.916295,0.910731,0.90338,0.857798,0.853067,0.851497,0.799984,...
0.730907,0.689608,0.638525,0.57848,0.440924];
Irange = min(I_exp):1:max(I_exp);
%%Initial guess & Brute-force minimize error function
a(1)=0.5; %Io: Reference exchange current density mA/cm2
a(2)=1200.00; %I_lim: Limiting current density mA/cm2
a(3)=2.5e-4; %total resistance kohm*cm2
a(4)=21.0; %cross-over current density mA/cm2
g = @(a) norm(V_mdl(a,I_exp)-V_exp);
ahat = fminsearch(g,a); % Values Calculated
V_cell = @(I) V_mdl(ahat,I);
%%Plotting and figures
hold on
figure(1)
scatter(I_exp,V_exp,'ok','MarkerFaceColor','b')
plot(Irange,V_cell(Irange),'r','linewidth',2)
grid on
title('Cell Voltage vs Current Density')
xlabel('Current Density [i, mA/cm^2]')
ylabel('Voltage [\eta, V]')
legend('-- Polarization Curve')
%%Calculation of power
I_t=I_exp';
_P_out(I_exp) = (V_cell(I_exp))* I_t;_
figure(2)
title('Fuel cell power')
xlabel('Current density (A/cm^2)');
ylabel('Power(Watts)');
plot(I_exp,P_out,'*');
grid on
hold on
Réponse acceptée
KSSV
le 20 Avr 2017
Replace:
P_out(I_exp) = (V_cell(I_exp))* I_t;
With
P_out = (V_cell(I_exp))* I_t;
Your I_exp are real numbers, you cannot use real numbers like indices. Only +ve integers are used to index arrays/ matrices.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Annotations 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!