Check for missing argument or incorrect argument data type in call to function 'int'.

I have an issue with performing ode45 when my function has an integral. I wish to integrate a function with one of my input variables defined for my function, but Matlab wants me to use syms to define the variable. Is there a way I can work around this issue? Any help is appreciated and thank you for your time.
function g = odefunction(t,p)
T = p(1); C = p(2);
Cp = (3.5*8.314)+(((1200/T)^2)*8.314*exp(1200/T)/((exp(1200/T)-1)^2));
Q = int(Cp,[298 T]); %Error message on this line
dTdt = ((10*Q)+(1000*(4.518*10^-8*exp(-100/(8.314*T)))))/100;
dCdt = 4-C+(4.518*10^-8*exp(-100/(8.314*T)));
g = [dTdt; dCdt];
%Script
tspan = [0 24];
initial = [298 5];
[t p] = ode45(@odefunction,tspan,initial);

 采纳的回答

It does not want to use the Symbolic Math Toolbox. It wants to use the correct integration function.
Try this:
function g = odefunction(t,p)
T = p(1); C = p(2);
Cp = @(T) (3.5*8.314)+(((1200./T).^2).*8.314.*exp(1200./T)./((exp(1200./T)-1).^2));
Q = integral(Cp,298,T); %Error message on this line
dTdt = ((10*Q)+(1000*(4.518*10^-8*exp(-100/(8.314*T)))))/100;
dCdt = 4-C+(4.518*10^-8*exp(-100/(8.314*T)));
g = [dTdt; dCdt];
end
%Script
tspan = [0 24];
initial = [298 5];
[t p] = ode45(@odefunction,tspan,initial);
figure
semilogy(t, p)
grid
The ‘Cp’ assignment needs to be transformed into an anonymous function, and int needs to be integral instead.
I added the plot call so I could see the result.
See the documentation section on Anonymous Functions for details.
.

更多回答(0 个)

类别

产品

版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by