How can I solve this vector lenght problem?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Thiago Brito
am 10 Dez. 2018
Kommentiert: madhan ravi
am 11 Dez. 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
0 Kommentare
Akzeptierte Antwort
Star Strider
am 10 Dez. 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 Kommentare
Star Strider
am 10 Dez. 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.
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!