How can I solve this vector lenght problem?

5 vues (au cours des 30 derniers jours)
Thiago Brito
Thiago Brito le 10 Déc 2018
Commenté : madhan ravi le 11 Déc 2018
Hi everyone!
It's been a long time since I used MATLAB for the last time. Unfortunatelly, I got rusty and I'm trying to make some examples to brush up my skills. One of this example drove into a bug that I have no idea what can be and how to solve it. I'm trying to use the ODE45 function (Rugge Kutta Method) but I got this error alert.
@(T,Y)TANKMODEL(T,Y) returns a vector of length 1, but the length of initial conditions vector is 2. The vector returned by @(T,Y)TANKMODEL(T,Y) and the initial conditions vector must have the same number of elements.
Can someone give me a north to solve this?
My code is:
clc;
close all;
format long
%Rugge Kutta Method
tspan = [0 5];
IC = [0 0];
[t,y] = ode45(@(t,y)tankmodel(t,y),tspan ,IC);
%Grafica
figure
plot(t,y)
title('Carbon Concentration');
xlabel('Time (s)');
ylabel('Concentration mg/m^3');
function dydt = tankmodel(t,y,z)
format long
%%%Dataset Parameters
Wgrill = 500; Qink = 100; Cink = 2;QE = 25;CE = 2;Ve= 840;Vk= 280;Ee= 25;Ek= 25;
Qoutk = Qink;
Qoute = Qink + QE;
% Equations
dydt = ((Wgrill + Qink*Cink - Qoutk*y + Ee*z - Ek*y)/Vk);
y(1)= 0;
dzdt = ((QE*CE + Qoutk*y - Qoute*z + Ek*y - Ee*z)/Ve);
z(1) = 0;
end

Réponse acceptée

Star Strider
Star Strider le 10 Déc 2018
Change your ‘tankmodel’ function to this and it works:
function dydt = tankmodel(t,yv)
format long
%%%Dataset Parameters
Wgrill = 500; Qink = 100; Cink = 2;QE = 25;CE = 2;Ve= 840;Vk= 280;Ee= 25;Ek= 25;
Qoutk = Qink;
Qoute = Qink + QE;
y = yv(1);
z = yv(2);
% Equations
dydt(1,:) = ((Wgrill + Qink*Cink - Qoutk*y + Ee*z - Ek*y)/Vk);
dydt(2,:) = ((QE*CE + Qoutk*y - Qoute*z + Ek*y - Ee*z)/Ve);
end
  3 commentaires
Star Strider
Star Strider le 10 Déc 2018
As always, my pleasure!
I am not certain what you are asking.
The time vector length is controlled by the ‘tspan’ argument.
The ‘y’ vector and the derivative your function returns (here ‘dydt’) are dictated by the function you are integrating. Here, both are (2x1) vectors.
madhan ravi
madhan ravi le 11 Déc 2018
+1 @ Star Strider I learn something in your answers each time :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics 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!

Translated by