Keep getting ode45 error: @(T,X)IRRI​GATIONMODE​L_NONLINEA​RP2(T,X,UT​,U) must return a column vector.

I am having a lot of trouble running the following code
Here is the main code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all; close all; clc
global C_r C_d C_p R_r R_d R_c R_p1 R_p2 R_w C_w
C_r = 1; C_d = 1; C_p = 1; R_r = 1; R_d = 1; R_c = 1; R_p1 = 1; R_p2 = 1; R_w = 1; C_w = 1; tspan = [0:0.1:50*24];
u_nom = 560; ut = tspan; u = u_nom*ones(length(ut),1); u(ut > 24 & ut < 48) = u_nom + 50;
T_w0 = 60000; T_p0 = 90000; T_d0 = 10000; x0 = [T_w0, T_p0, T_d0];
opts = odeset('RelTol',1e-10,'AbsTol',1e-20);
[t,x] = ode45(@(t,x) irrigationModel_nonlinearp2(t,x,ut,u),tspan,x0,opts);
T_w = x(:,1); T_p = x(:,2); T_d = x(:,3); t = t/24;
subplot(411); plot(ut/24,u); subplot(412); plot(t,T_w-T_w0); subplot(413); plot(t,T_p-T_p0); subplot(414); plot(t,T_d-T_d0);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
And here is the called function:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function dxdt = irrigationModel_nonlinearp2(t,x,ut,u)
global C_r C_d C_p R_r R_d R_c R_p1 R_p2 R_w C_w
T_w = [0:1:12000];
T_p = [0:1:12000];
T_d = [0:1:12000];
Tw = T_w*x(1);
Tp = T_p*x(2);
Td = T_d*x(3);
u = interp1(ut,u,t);
dxdt = [-((1/(R_w*C_w))+(1/(R_p1*C_w)))*Tw + (1/(R_p1*C_w))*Tp + u/C_w; (1/(R_p2*C_d))*Tw - ((1/(R_p2*C_d))+(1/(R_c*C_d)))*Td; (1/(R_p1*C_p))*Tw + (1/(R_p2*C_p))*Td - ((1/(R_p1*C_p))+(1/(R_p2*C_p)))*Tp];

Answers (1)

When you call irrigationModel_nonlinearp2 with the first element of your time span vector, your initial condition vector, and the extra parameters as its input, does it return a row vector, a column vector, or something that isn't a vector?

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2014b

Asked:

on 26 Sep 2018

Answered:

on 27 Sep 2018

Community Treasure Hunt

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

Start Hunting!