I want to integrate froma function

1 Ansicht (letzte 30 Tage)
Rodrigo Blas
Rodrigo Blas am 22 Mär. 2020
Kommentiert: Ameer Hamza am 22 Mär. 2020
function prob7f=xequil(x,cao,ep,k2,kc,Fao)
ca=cao*(1-x)./(1+ep*x);
cb=cao*(1-x)./(1+ep*x);
cc=2*cao*x./(1+ep*x);
ra=-(k2*(ca-(cb*cc)./kc));
prob7f=Fao./(-ra);
end
z=@xequil;
volpfreq=integral(z,0,xf);
>> Jallohw5p7
Not enough input arguments.
Error in xequil (line 3)
ca=cao*(1-x)./(1+ep*x);
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] =
iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in Jallohw5p7 (line 32)
volpfreq=integral(z,0,xf);
All other varables are defined, except x of course, which is the variables I want to solve for.
  2 Kommentare
Ameer Hamza
Ameer Hamza am 22 Mär. 2020
What are values of cao,ep,k2,kc,Fao? Where are they defined? You need to define them inside the function.
Rodrigo Blas
Rodrigo Blas am 22 Mär. 2020
%%Data
T1=50+273.15; %%k
T2=127+273.15; %%k
Fao=2.5; %%mol/min
P=10; %%atm
k1=10^-4; %%min^-1
R=8.314; %j/k*mol
R1=8.206*10^-5*1000; %%atm*dm^3/K*mol
E=85*1000; %%j/mol
kc=.025; %%mol/dm^2
alpha=.001; %%dm^3
t=3*60; %%min
Nao=450;
xf=.90;
xo=0;
%%Calculated Data
k2=k1*exp(E/R*(1/T1-1/T2)); %%min^-1
cao=P/(T2*R1); %%mol/dm^3
ep=2+1-1;
xe=jallohw5p7f(cao,ep,kc,xo);
xfe=xe*.9;
pfrxeq=@xequil;
volcstr=(Fao*xf)*(1+ep*xf)/(k2*cao*(1-xf)); %%dm^3
fun=@(x) Fao/(cao*k2)*(1+ep*x)./(1-x);
z=@xequil;
%%funeeqpfr=@(x) Fao/(-ra);
volpfreq=integral(z,0,xf);
volpfr=integral(fun,0,xf); %%dm^3
t=3*60;
Nao=450;
v7e=Nao/(t*k2*cao)*log(1/(1-xf));
[x,y]=ode45(@(x,y) jallohwfun7(alpha,ep,y,cao,k2,Fao),[0 500],[1 0]);
%%funeq=@(x) Fao./(-(k2*cao/(1+ep*x)*((1-x)-(4*cao^2*x^3)/((1+ep*x)^2)*kc)));
%%volpfreq=integral(funeq,0,xf);
plot(x,y(:,1),'r','LineWidth',1);
hold on;
plot(x,y(:,2),'k','LineWidth',1);
legend('Pressure', 'Conversion');
xlabel('Volume [dm^3]');
ylabel('Pressure [atm] & Conversion');
title('Pressure and Conversion vs Volume ');
Here is my whole script..
Really? I cant pass them through the function?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 22 Mär. 2020
The integral function should be called like this
z=@(x) xequil(x, cao, ep, k2, kc, Fao);
volpfreq=integral(z,0,xf);
Also change the following line in the function xequil
ra=-(k2*(ca-(cb*cc)./kc));
with
ra=-(k2.*(ca-(cb.*cc)./kc));
  2 Kommentare
Rodrigo Blas
Rodrigo Blas am 22 Mär. 2020
function prob7f=xequil(x,cao,ep,k2,kc,Fao)
ca=cao*(1-x)./(1+ep*x);
cb=cao*(1-x)./(1+ep*x);
cc=2*cao*x./(1+ep*x);
ra=-(k2.*(ca-(cb.*cc)./kc));
prob7f=(Fao/(-ra));
end
z=@(x) xequil(x,cao,ep,k2,kc,Fao);
volpfreq=integral(z,0,xf);
>> Jallohw5p7
Error using /
Matrix dimensions must agree.
Error in xequil (line 8)
prob7f=(Fao/(-ra));
Error in Jallohw5p7>@(x)xequil(x,cao,ep,k2,kc,Fao)
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] =
iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in Jallohw5p7 (line 30)
volpfreq=integral(z,0,xf);
This is the new error I get
Ameer Hamza
Ameer Hamza am 22 Mär. 2020
You also changed the last line
prob7f=(Fao/(-ra));
change it back to
prob7f=(Fao./(-ra));

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Computations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by