I have 9 equations and 9 unknowns that I need to solve for, but when I set up the code and run it I get the following:
"Warning: Unable to find explicit solution. For options, see help.
In sym/solve (line 317)
In HW2_PartA (line 65)
ans =
Empty sym: 0-by-1"
I have tried using both the solve functions and the vpasolve functions and I receive the same message each time.
The code is:
clear all
clc
syms T0 nO2 nH2 nH nOH nH2O nO lO lH
t = T0/1000;
R = 8.314;
nF = 1;
nOX = 11/32;
P0 = 5.3e6; % Pa
Pstp = 101.3e3;%Pa
hfH2 = 0; %j/mol
hfO2 = 0; %j/mol
hfH2O = -241.82e3;% j/mol
hfO = 249.19e3; %j/mol
hfH = 218e3;%J/mol
hfOH = 39.46e3;%j/mol
oxygengas = [20.9111 10.721071 -2.020498 0.046449 9.245722 5.337651 237.6185 0.00];
hydrogengas = [43.4136 -4.2931 1.2724 -0.0969 -20.5339 -38.5152 162.0814 0.00];
hydrogen = [20.7860 0.0000 -0.0000 0.0000 0.0000 211.8020 139.8711 217.9990];
OHgas = [28.7470 4.7145 -0.8147 0.0547 -2.7478 26.4144 214.1166 38.9871];
water = [41.9643 8.6221 -1.4998 0.0981 -11.1576 -272.1797 219.7809 -241.8264];
%Enthalpy
hO2 = 1000*(oxygengas*t + oxygengas(2)*(t^2)/2 + oxygengas(3)*(t^3)/3 + oxygengas(4)*(t^4)/4 -
oxygengas(5)/t + oxygengas(6) - oxygengas(8));
hH2 = 1000*(hydrogengas(1)*t + hydrogengas(2)*(t^2)/2 + hydrogengas(3)*(t^3)/3 + hydrogengas(4)*
(t^4)/4 - hydrogengas(5)/t + hydrogengas(6) - hydrogengas(8));
hH = 1000*(hydrogen(1)*t + hydrogen(2)*(t^2)/2 + hydrogen(3)*(t^3)/3 + hydrogen(4)*(t^4)/4 -
hydrogen(5)/t + hydrogen(6) - hydrogen(8));
hOH = 1000*(OHgas(1)*t + OHgas(2)*(t^2)/2 + OHgas(3)*(t^3)/3 + OHgas(4)*(t^4)/4 - OHgas(5)/t +
OHgas(6) - OHgas(8));
hO = hH;
hH2O = 1000*(water(1)*t + water(2)*(t^2)/2 + water(3)*(t^3)/3 + water(4)*(t^4)/4 - water(5)/t +
water(6) - water(8));
%Entropy
sO2 = oxygengas(1)*log(t) + oxygengas(2)*t + oxygengas(3)*(t^2)/2 +oxygengas(4)*(t^3)/3 -
oxygengas(5)/(2*t^2) +oxygengas(7);
sH2 = hydrogengas(1)*log(t) + hydrogengas(2)*t + hydrogengas(3)*(t^2)/2 +hydrogengas(4)*(t^3)/3 -
hydrogengas(5)/(2*t^2) +hydrogengas(7);
sH = hydrogen(1)*log(t) + hydrogen(2)*t + hydrogen(3)*(t^2)/2 +hydrogen(4)*(t^3)/3 -
hydrogen(5)/(2*t^2) +hydrogen(7);
sOH = OHgas(1)*log(t) + OHgas(2)*t + OHgas(3)*(t^2)/2 +OHgas(4)*(t^3)/3 - OHgas(5)/(2*t^2) +OHgas(7);
sO = (5/2)*R*log(T0/298.15) + 161.003;
sH2O = water(1)*log(t) + water(2)*t + water(3)*(t^2)/2 +water(4)*(t^3)/3 - water(5)/(2*t^2)
+water(7);
%Mass continuity
eqn1 = 2*nO2 + nOH + nO +nH2O - 2*nOX == 0;
eqn2 = 2*nH2 + 2*nH2O + nOH + nH - 2*nF == 0;
%Minimizing Gibbs Free Energy
%Oxygen Gas
eqn3 = hO2 + hfO2 - T0*sO2 + R*T0*log(P0/Pstp) + R*T0*log(nO2/(nO2+nH2+nH+nOH+nO+nH2O)) + 2*lO ==0 ;
%Hydrogen Gas
eqn4 = hH2 + hfH2 - T0*sH2 + R*T0*log(P0/Pstp) + R*T0*log(nH2/(nO2+nH2+nH+nOH+nO+nH2O)) + 2*lH == 0;
%Hydrogen
eqn5 = hH + hfH - T0*sH + R*T0*log(P0/Pstp) + R*T0*log(nH/(nO2+nH2+nH+nOH+nO+nH2O)) + lH == 0;
%OH Gas
eqn6 = hOH + hfOH - T0*sOH + R*T0*log(P0/Pstp) + R*T0*log(nOH/(nO2+nH2+nH+nOH+nO+nH2O)) + lO + lH ==
0;
%Oxygen
eqn7 = hO + hfO - T0*sO + R*T0*log(P0/Pstp) + R*T0*log(nO/(nO2+nH2+nH+nOH+nO+nH2O)) + lO == 0;
%Water
eqn8 = hH2O + hfH2O - T0*sO2 + R*T0*log(P0/Pstp) + R*T0*log(nH2O/(nO2+nH2+nH+nOH+nO+nH2O)) + 2*lH +
lO == 0;
% Enthalpy Balance
eqn9 = nO2*hO2 + nH2*hH2 + nH*hH + nOH*hOH + nO*hO + nH2O*hH2O - nOX*hfO2 - nF*hfH2 + nO2*hfO2 +
nH2*hfH2 + nH*hfH + nOH*hfOH + nO*hfOH + nH2O*hfH2O == 0;
eqns = [eqn1,eqn2,eqn3,eqn4,eqn5, eqn6, eqn7, eqn8, eqn9];
sol = solve([eqn1,eqn2,eqn3,eqn4,eqn5,eqn6,eqn7,eqn8,eqn9], [T0 nO2 nH2 nH nOH nH2O nO lO lH]);
sol.T0
Related
I´m attempting to use the Runge-Kutta method to compare it to the lsode function. But it is performing rather poorly, every other method I used (forwards and backwards Euler, Heun) to compare to lsode do a way better job to the point they are almost indistinguishable from lsode.
This is what my code returns
https://i.stack.imgur.com/vJ6Yi.png
If anyone can point out a way to improve it or if I'm doing something wrong I´d appreciate it.
The following is what I use for the Runge-Kutta method
%Initial conditions
u(1) = 1;
v(1) = 2;
p(1) = -1/sqrt(3);
q(1) = 1/sqrt(3);
%Graf interval / step size
s0 = 0;
sf = 50;
h = 0.25;
n=(sf-s0)/h;
s(1) = s0;
%-----------------------------------------------------------------------%
for j = 2:n
i = j-1;
k1_u(j) = p(i);
k1_v(j) = q(i);
k1_p(j) = (-2*v(i)*p(i)*q(i)) / (u(i)*u(i) + v(i)*v(i) + 1);
k1_q(j) = (-2*u(i)*p(i)*q(i)) / (u(i)*u(i) + v(i)*v(i) + 1);
u1(j) = p(i) + (1/2)*k1_u(j)*h;
v1(j) = q(i) + (1/2)*k1_v(j)*h;
p1(j) = (-2*v(i)*p(i)*q(i)) / (u(i)*u(i) + v(i)*v(i) + 1) + (1/2)*k1_p(j)*h;
q1(j) = (-2*u(i)*p(i)*q(i)) / (u(i)*u(i) + v(i)*v(i) + 1) + (1/2)*k1_q(j)*h;
k2_u(j) = p1(j);
k2_v(j) = q1(j);
k2_p(j) = (-2*v1(j)*p1(j)*q1(j)) / (u1(j)*u1(j) + v1(j)*v1(j) + 1);
k2_q(j) = (-2*u1(j)*p1(j)*q1(j)) / (u1(j)*u1(j) + v1(j)*v1(j) + 1);
u2(j) = p(i) + (1/2)*k2_u(j)*h;
v2(j) = q(i) + (1/2)*k2_v(j)*h;
p2(j) = (-2*v(i)*p(i)*q(i)) / (u(i)*u(i) + v(i)*v(i) + 1) + (1/2)*k2_p(j)*h;
q2(j) = (-2*u(i)*p(i)*q(i)) / (u(i)*u(i) + v(i)*v(i) + 1) + (1/2)*k2_q(j)*h;
k3_u(j) = p2(j);
k3_v(j) = q2(j);
k3_p(j) = (-2*v2(j)*p2(j)*q2(j)) / (u2(j)*u2(j) + v2(j)*v2(j) + 1);
k3_q(j) = (-2*u2(j)*p2(j)*q2(j)) / (u2(j)*u2(j) + v2(j)*v2(j) + 1);
u3(j) = p(i) + k3_u(j)*h;
v3(j) = q(i) + k3_v(j)*h;
p3(j) = (-2*v(i)*p(i)*q(i)) / (u(i)*u(i) + v(i)*v(i) + 1) + k3_p(j)*h;
q3(j) = (-2*u(i)*p(i)*q(i)) / (u(i)*u(i) + v(i)*v(i) + 1) + k3_q(j)*h;
k4_u(j) = p3(j);
k4_v(j) = q3(j);
k4_p(j) = (-2*v3(j)*p3(j)*q3(j)) / (u3(j)*u3(j) + v3(j)*v3(j) + 1);
k4_q(j) = (-2*u3(j)*p3(j)*q3(j)) / (u3(j)*u3(j) + v3(j)*v3(j) + 1);
s(j) = s(j-1) + h;
u(j) = u(j-1) + (h/6)*(k1_u(j) + 2*k2_u(j) + 2*k3_u(j) + k4_u(j));
v(j) = v(j-1) + (h/6)*(k1_v(j) + 2*k2_v(j) + 2*k3_v(j) + k4_v(j));
p(j) = p(j-1) + (h/6)*(k1_p(j) + 2*k2_p(j) + 2*k3_p(j) + k4_p(j));
q(j) = q(j-1) + (h/6)*(k1_q(j) + 2*k2_q(j) + 2*k3_q(j) + k4_q(j));
endfor
subplot(2,3,1), plot(s,u);
hold on; plot(s,v); hold off;
title ("Runge-Kutta");
h = legend ("u(s)", "v(s)");
legend (h, "location", "northwestoutside");
set (h, "fontsize", 10);
You misunderstood something in the method. The intermediate values for p,q are computed the same way as the intermediate values for u,v, and both are "Euler steps" with the last computed slopes, not separate slope computations. For the first ones that is
u1(j) = u(i) + (1/2)*k1_u(j)*h;
v1(j) = v(i) + (1/2)*k1_v(j)*h;
p1(j) = p(i) + (1/2)*k1_p(j)*h;
q1(j) = q(i) + (1/2)*k1_q(j)*h;
The computation for the k2 values then is correct, the next midpoints need to be computed correctly via "Euler steps", etc.
I have the following script
clc; clear all; close all;
syms x n
f = x;
L = 1;
subplot(2,1,1)
h = ezplot(f,[-L,L])
set(h, 'Color','r','LineWidth',1)
a0 = (1/L) * int(f * cos(0* pi*x/L),-L,L)
an = (1/L) * int(f * cos(n* pi*x/L),-L,L)
bn = (1/L)* int(f* sin(n* pi*x/L),-L,L)
fx = a0/2 + symsum((an* cos(n*pi*x/L) + bn* sin(n*pi*x/L)),n,1,5)
% for n =5, the answer: fx = (2*sin(pi*x))/pi - sin(2*pi*x)/pi +
%(2*sin(3*pi*x))/(3*pi) - sin(4*pi*x)/(2*pi) + (2*sin(5*pi*x))/(5*pi)
hold on
h = ezplot(fx,[-L,L])
grid on
%Solution with complex Fourier
c0 = (1/(2*L))*int(f*exp(-j*0*pi*x/L),-L,L)
cn = (1/(2*L))*int(f*exp(-j*n*pi*x/L),-L,L)
subplot(2,1,2)
h = ezplot(f,[-L,L])
set(h, 'Color','r','LineWidth',1)
fx_c = c0 + symsum(cn*exp(j*n*pi*x/L),n,-5,-1) + ...
symsum(cn*exp(j*n*pi*x/L),n,1,5) % n for complex -5,5
hold on
h = ezplot(fx_c,[-L,L])
grid on
My question: Since the answer of fx should be equal to fx_c (complex fourier). We can see from the figures produced by these 2 functions. They are same. But
fx =
(2*sin(pi*x))/pi - sin(2*pi*x)/pi + (2*sin(3*pi*x))/(3*pi) - sin(4*pi*x)/(2*pi) + (2*sin(5*pi*x))/(5*pi)
and
fx_c =
exp(-pi*x*i)*((pi*i - 1)/(2*pi^2) + (pi*i + 1)/(2*pi^2)) - exp(pi*x*i)*((pi*i - 1)/(2*pi^2) + (pi*i + 1)/(2*pi^2)) - exp(-pi*x*2*i)*((pi*2*i - 1)/(8*pi^2) + (pi*2*i + 1)/(8*pi^2)) + exp(pi*x*2*i)*((pi*2*i - 1)/(8*pi^2) + (pi*2*i + 1)/(8*pi^2)) + exp(-pi*x*3*i)*((pi*3*i - 1)/(18*pi^2) + (pi*3*i + 1)/(18*pi^2)) - exp(pi*x*3*i)*((pi*3*i - 1)/(18*pi^2) + (pi*3*i + 1)/(18*pi^2)) - exp(-pi*x*4*i)*((pi*4*i - 1)/(32*pi^2) + (pi*4*i + 1)/(32*pi^2)) + exp(pi*x*4*i)*((pi*4*i - 1)/(32*pi^2) + (pi*4*i + 1)/(32*pi^2)) + exp(-pi*x*5*i)*((pi*5*i - 1)/(50*pi^2) + (pi*5*i + 1)/(50*pi^2)) - exp(pi*x*5*i)*((pi*5*i - 1)/(50*pi^2) + (pi*5*i + 1)/(50*pi^2))
How to convert fx_c to be fx?
They are related by Euler's formula. You can check it with rewrite command:
>> rewrite(exp(1i*x), 'cos')
ans =
cos(x) + sin(x)*1i
Applying it to your function and simplifying a bit, you can get to the same expression:
>> expand(rewrite(fx_c, 'cos'), 'ArithmeticOnly', true)
ans =
(2*sin(pi*x))/pi - sin(2*pi*x)/pi + (2*sin(3*pi*x))/(3*pi) - sin(4*pi*x)/(2*pi) + (2*sin(5*pi*x))/(5*pi)
>> fx
fx =
(2*sin(pi*x))/pi - sin(2*pi*x)/pi + (2*sin(3*pi*x))/(3*pi) - sin(4*pi*x)/(2*pi) + (2*sin(5*pi*x))/(5*pi)
Using DeMorgan's theorem show that:
a. (A + B)'(A' +B)' = 0
b. A + A'B + A'B' = 1
Boolean expression F = x'y + xyz':
Derive an algebraic expression for the complement F'
Show that F·F' = 0
Show that F + F' = 1
Please Help me
Assuming you know how DeMorgan's law works and you understand the basics of AND, OR, NOT operations:
1.a) (A + B)'(A' + B)' = A'B'(A')'B' = A'B'AB' = A'AB'B' = A'AB' = 0 B' = 0.
I used two facts here that hold for any boolean variable A:
AA' = 0 (when A = 0, A' = 1 and when A = 1, A' = 0 so (AA') has to be 0)
0A = 0 (0 AND anything has to be 0)
1.b) A + A'B + A'B' = A + A'(B + B') = A + A' = 1.
I used the following two facts that hold for any boolean variables A, B and C:
AB + AC = A(B + C) - just like you would do with numeric variables and multiplication and addition. Only here we work with boolean variables and AND (multiplication) and OR (addition) operations.
A + A' = 0 (when A = 0, A' = 0 and when A = 1, A' = 0 so (A + A') has to be 1)
2.a) Let's first derive the complement of F:
F' = (x'y + xyz')' = (x'y)'(xyz')' = (x + y')((xy)' + z) = (x + y')(x' + y' + z) = xx' + xy' + xz + x'y' + y'y' + y'z = 0 + xy' + xz + x'y' + y' + y'z = xy' + xz + y'(x + 1) + y'z = xy' + xz + y' + y'z = xy' + xz + y'(z + 1) = xy' + y' + xz = y'(x + 1) = xz + y'.
There is only one additional fact that I used here, that for any boolean variables A and B following holds:
A + AB = A(B + 1) = A - logically, variable A completely determines the output of such an expression and part AB cannot change the output of entire expression (you can check this one with truth tables if it's not clear, but boolean algebra should be enough to understand). And of course, for any boolean variable A + 1 = A.
2.b) FF' = (x'y + xyz')(xz + y') = x'yxz + x'yy' + xyz'xz + xyz'y'.
x'yxz = (xx')yz = 0xz = 0
xyy'= x0 = 0
xyz'xz = xxy(zz') = xy0 = 0
xyz'y' = xz'(yy') = xz'0 = 0
Therefore, FF' = 0.
2.c) F + F' = x'y + xyz' + xz + y'
This one is not so obvious. Let's start with two middle components and see what we can work out:
xyz' + xz = x(yz' + z) = x(yz' + z(y + y')) = x(yz' + yz + y'z) = x(y(z + z') + y'z) = x(y + y'z) = xy + xy'z.
I used the fact that we can write any boolean variable A in the following way:
A = A(B + B') = AB + AB' as (B + B') evaluates to 1 for any boolean variable B, so initial expression is not changed by AND-ing it together with such an expression.
Plugging this back in F + F' expression yields:
x'y + xy + xy'z + y' = y(x + x') + y'(xz + 1) = y + y' = 1.
I've been trying to port a set of differential equations from Matlab R2014b to python 3.4.
I've used both odeint and ode, with no satisfactory results. The expected results are the ones I get from Matlab where xi = xl and xj = xk with an offset of 180 in phase for each group, as you can see from the image below.
The code I'm running in Matlab is the following:
function Fv = cpg(t, ini_i);
freq = 2;
%fixed parameters
alpha = 5;
beta = 50;
miu = 1;
b = 1;
%initial conditions
xi = ini_i(1);
yi = ini_i(2);
xj = ini_i(3);
yj = ini_i(4);
xk = ini_i(5);
yk = ini_i(6);
xl = ini_i(7);
yl = ini_i(8);
ri = sqrt(xi^2 + yi^2);
rj = sqrt(xj^2 + yj^2);
rk = sqrt(xk^2 + yk^2);
rl = sqrt(xl^2 + yl^2);
%frequency for all oscillators
w_swing = 1;
w_stance = freq*w_swing;
%Coupling matrix, that determines a walking gate for
%a quadruped robot.
k = [ 0, -1, -1, 1;
-1, 0, 1, -1;
-1, 1, 0, -1;
1, -1, -1, 0];
%Hopf oscillator 1
omegai = w_stance/(exp(-b*yi)+1) + w_swing/(exp(b*yi)+1);
xi_dot = alpha*(miu - ri^2)*xi - omegai*yi;
yi_dot = beta*(miu - ri^2)*yi + omegai*xi + k(1,2)*yj + k(1,3)*yk + k(1,4)*yl;
%Hopf oscillator 2
omegaj = w_stance/(exp(-b*yj)+1) + w_swing/(exp(b*yj)+1);
xj_dot = alpha*(miu - rj^2)*xj - omegaj*yj;
yj_dot = beta*(miu - rj^2)*yj + omegaj*xj + k(2,1)*yi + k(2,3)*yk + k(2,4)*yl;
%Hopf oscillator 3
omegak = w_stance/(exp(-b*yk)+1) + w_swing/(exp(b*yj)+1);
xk_dot = alpha*(miu - rk^2)*xk - omegak*yk;
yk_dot = beta *(miu - rk^2)*yk + omegak*xk + k(3,4)*yl + k(3,2)*yj + k(3,1)*yi;
%Hopf oscillator 4
omegal = w_stance/(exp(-b*yl)+1) + w_swing/(exp(b*yl)+1);
xl_dot = alpha*(miu - rl^2)*xl - omegal*yl;
yl_dot = beta *(miu - rl^2)*yl + omegal*xl + k(4,3)*yk + k(4,2)*yj + k(4,1)*yi;
%Outputs
Fv(1,1) = xi_dot;
Fv(2,1) = yi_dot;
Fv(3,1) = xj_dot;
Fv(4,1) = yj_dot;
Fv(5,1) = xk_dot;
Fv(6,1) = yk_dot;
Fv(7,1) = xl_dot;
Fv(8,1) = yl_dot;
However, when I moved the code to python I get an output like this.
In python I ran the ODE solver using the same time step as in Matlab and using solver 'dopri5', which is supposed to be equivalent to the one I'm using in Matlab, ode45. I use the same initial conditions in both cases. I've used both odeint and ode with similar results.
I just started programming in Python and it is my first implementation using Scipy and Numpy so maybe I'm misinterpreting something?
def cpg(t, ini, k, freq):
alpha = 5
beta = 50
miu = 1
b = 1
assert freq == 2
'Initial conditions'
xi = ini[0]
yi = ini[1]
xj = ini[2]
yj = ini[3]
xk = ini[4]
yk = ini[5]
xl = ini[6]
yl = ini[7]
ri = sqrt(xi**2 + yi**2)
rj = sqrt(xj**2 + yj**2)
rk = sqrt(xk**2 + yk**2)
rl = sqrt(xl**2 + yl**2)
'Frequencies for each oscillator'
w_swing = 1
w_stance = freq * w_swing
'First Oscillator'
omegai = w_stance/(exp(-b*yi)+1) + w_swing/(exp(b*yi)+1)
xi_dot = alpha*(miu - ri**2)*xi - omegai*yi
yi_dot = beta*(miu - ri**2)*yi + omegai*xi + k[1]*yj + k[2]*yk + k[3]*yl
'Second Oscillator'
omegaj = w_stance/(exp(-b*yj)+1) + w_swing/(exp(b*yj)+1)
xj_dot = alpha*(miu - rj**2)*xj - omegaj*yj
yj_dot = beta*(miu - rj**2)*yj + omegaj*xj + k[4]*yi + k[6]*yk + k[7]*yl
'Third Oscillator'
omegak = w_stance/(exp(-b*yk)+1) + w_swing/(exp(b*yk)+1)
xk_dot = alpha*(miu - rk**2)*xk - omegak*yk
yk_dot = beta*(miu - rk**2)*yk + omegak*xk + k[8]*yi + k[9]*yj + k[11]*yl
'Fourth Oscillator'
omegal = w_stance/(exp(-b*yl)+1) + w_swing/(exp(b*yl)+1)
xl_dot = alpha*(miu - rl**2)*xl - omegal*yl
yl_dot = beta*(miu - rl**2)*yl + omegal*xl + k[12]*yi + k[13]*yj + k[14]*yk
return [xi_dot, yi_dot, xj_dot, yj_dot, xk_dot, yk_dot, xl_dot, yl_dot]
The way that I'm calling the ODE is as follows:
X0 = [1,-1, 0,-1, 1,1, 0,1]
r = ode(cpg).set_integrator('dopri5')
r.set_initial_value(X0).set_f_params(k_trot, 2)
t1 = 30.
dt = .012
while r.successful() and r.t < (t1-dt):
r.integrate(r.t+dt)
I hope I was clear enough.
Any suggestions?
I have a problem when running my simulink file that have constant - pid controller - s-function - scope
I got an error
"Error, M-File S-function 'chiu_sfcn' in 'project1_simu/S-Function' is expecting 0 parameter(s) while 9 were provided"
function [sys,x0,str,ts]= chiu_sfcn(t,x,u,flag)
switch flag
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys = mdlDerivatives(t,x,u);
case 3,
sys = mdlOutputs(t,x,u);
case 9
sys =[];
otherwise
error(['unhandled flag =',num2str(flag)]);
end
function [sys,x0,str,ts] = mdlInitializeSizes()
ssSetInputPortWidth(S,0,11)
s = simsizes;
s.NumContStates = 11;
s.NumDiscStates = 0;
s.NumOutputs = 11;
s.NumInputs = 1;
s.DirFeedthrough = 0;
s.NumSampleTimes = 1;
sys = simsizes(s) ;
x0 = [0.0258,0,0,0,0,0,0,0,8.83];
str=[] ;
ts = [0 0];
function sys = mdlDerivatives (t,x,u)
% Reactor temperature
u=303.15;
T=u;
B=0.03;
I0=0.0258;
M0=8.83;
F=0.58;
dp=1.2;
Tgp=3.87e2;
Kd = (6.32e16*exp(-15.43e3/T));
Kt0 = 5.88e9*exp(-701/(1.987*T));
Kp0 = 2.95e7*exp(-4353/(1.987*T));
Tet = ((1.1353e-22)/I0)*exp(17420/T);
Tep = 5.4814e-16*exp(13982/T);
A=0.168-(8.21e-6*((T-Tgp)^2));
dm = 0.973-1.164e-3*(T-273.15);
Fev = (dm - dp)/dp ;
Fvm = (1 - x(2))/(1 + (Fev*x(2)));
g = exp(2.303*Fvm/(A + B*Fvm));
Kt = (Kt0*g)/(g + (Tet*x(3)*Kt0));
Kp = (Kp0*g)/(g + (Tep*x(3).*Kp0));
sys(1)=-Kd*I - ((Fev*I.*P0.*(1-X)*Kp)/(1+Fev*X));
sys(2)=Kp*(1-X)*P0;
sys(3)=(-Fev*P0.^2*(1-X)*Kp)/(1+Fev*X) + 2*F*Kd*I - Kt*P0.^2;
sys(4)=(-Fev*P0.*P1.*(1-X)*Kp)/(1+Fev*X)+ 2*F*Kd*I - Kt*P0.*P1 + (Kp*P0.*M0*(1-X))/(1+Fev*X);
sys(5)=(-Fev*P2.*P0.*(1-X)*Kp)/(1+Fev*X) + 2*F*Kd*I - Kt*x(3).*x(5) + (Kp*M0*(1-X)*(2*P1+P0))/(1+Fev*X);
sys(6)=(-Fev*Q0.*P0.*(1-X)*Kp)/(1+Fev*X) + Ktd*P0.^2 + 0.5*Ktc*P0.^2;
sys(7)=(-Fev*Q1.*P0.*(1-X)*Kp)/(1+Fev*X) + Ktd*P0.*P1 + Ktc*P0.*P1;
sys(8)=(-Fev*Q2.*P0.*(1-X)*Kp)/(1+Fev*X) + Ktd*P0.*P2 + Ktc*(P1.*P0+P1.^2);
sys(9)=(-Kp*P0*M0*(1-X)/(1+Fev*X))*((Fev*(1-X)/(1+Fev*X))+1);
sys(10)=(-Fev*P0.*Q2.*(1 - X)./(1 + Fev*X)).*Kp + Ktd*P0.*P2 + Ktc*(P1.*P0 + P1.^2);
sys(11)=(-Kp*P0*M0*(1 - X)./(1 + Fev*X)).*((Fev*(1 - X)./(1 + Fev*X)) + 1);
function sys = mdlOutputs(t,x,u)
sys(1)=x(6);
% sys(2)=x(2);
% sys(3)=x(3);
% sys(4)=x(4);
% sys(5)=x(5);
% sys(6)=x(6);
% sys(7)=x(7);
% sys(8)=x(8);
% sys(9)=x(9);
% sys(10)=x(10);
% sys(11)=x(11);
My questions is about the error. What does it mean? And where to identify the source of the problem?
Try looking on the S-function block that is setup to call chiu_sfcn. Are there any values in the dialog field S-function parameters, from the error there probably are 9 values entered into this dialog field.
If you need those parameters passed in, you need to update the interface to your s-function, if you don't want them, remove them from the dialog.