Undefined operator '*' for input arguments of type 'struct'.

I need to call an ode15s to solve the system of odes described below but I keep getting this error for line 25 (vec(10)) and I can't find any documentation that can help me...
M, AU, a and No are all (1x1) constants.
Any help is welcome and thanks in advance
function [Lt,vec]=reformerdaes(Lt,x,M,AU,a,No)
yo=[0.015064 0.408652 0.024897 0.437598 0.090726 0 0.023063];
for i = 1:7
y(i)=[x(i+6)];
end
srr=@srreaction;
r=srr(x(7),y,x(2));
h=@enthalpy1;
Hi=h(y,x(2));
Ho=h(yo,x(1));
vec(1)=M*(-r(1)); % CH4
vec(2)=M*(-r(1)-r(2)); % H2O
vec(3)=M*(r(1)-r(2)); % CO
vec(4)=M*(3*r(1)+r(2)); % H2
vec(5)=M*r(2); % CO2
vec(6)=AU*(x(1)-x(2));
vec(7)=-vec(4);
vec(8)=x(7)-a*Lt;
vec(9)=x(6)-x(4)*Hi;
vec(10)=x(5)-No*Ho;
end

Answers (1)

While not your problem, a stylistic note--
for i = 1:7
y(i)=[x(i+6)];
end
should be written in Matlab as
y=x([1:7]+6);
anad it would also be better to have documentation for the "magic number" 6.
...
h=@enthalpy1;
The problem would seem to be in the return the function enthaly1 provides--apparently it is a structure instead of a double although you don't show us enough to know. How does it get its inputs, btw, hopefully they're not global; "there be dragons" from a code reliability standpoint.

2 Comments

Thanks for the comment friend.
For the record, I have changed my function and the way I call it, since the arguments were not in a correct sequence. I believe that the error occurred because the script received options as a value. I don't get the error anymore. :)
initialval=[8.1218 38.2249 0 0 0 0 1.4333 ...
Hin Hout Pin Tin Tout ]; % 12 variables ( 2 algebraic )
MASS=eye(12); MASS(10,10)=0; MASS(11,11)=0; MASS(12,12)=0;
options=odeset('reltol',1e-4,'abstol',1e-4,'mass',MASS);
[Lt,n1,n2,n3,n4,n5,n6,n7,Hi,Ho,P,Ti,To]= ...
ode15s(@(Lt,dfdz) reformerdaes(Lt,initialval,M,AU,a,Nout), ...
Lt,initialval,options);
and my function
function dfdz=reformerdaes(Lt,x,M,AU,a,No)
yo=[0.015064 0.408652 0.024897 0.437598 0.090726 0 0.023063];
n=x([1:7])
Ni=sum(n);
y=n/Ni;
srr=@srreaction;
r=srr(x(10),y,x(11));
h=@enthalpy1;
dfdz=zeros(12,1);
dfdz(1)=M*(-r(1)); % CH4
dfdz(2)=M*(-r(1)-r(2)); % H2O
dfdz(3)=M*(r(1)-r(2)); % CO
dfdz(4)=M*(3*r(1)+r(2)); % H2
dfdz(5)=M*r(2); % CO2
dfdz(6)=0; % O2
dfdz(7)=0; % N2
dfdz(8)=AU*(x(12)-x(11));
dfdz(9)=-dfdz(6);
dfdz(10)=-a;
dfdz(11)=x(8)-Ni*h(y,x(11));
dfdz(12)=x(9)-No*h(yo,x(12));
end
My problem now is that the index value is greater than 1, which I try to fix...

Sign in to comment.

Asked:

on 2 Apr 2016

Commented:

dpb
on 2 Apr 2016

Community Treasure Hunt

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

Start Hunting!