Must return a column vector error when using "ode45" (2024)

77 views (last 30 days)

Show older comments

Talha on 20 Aug 2024 at 5:51

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2146499-must-return-a-column-vector-error-when-using-ode45

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2146499-must-return-a-column-vector-error-when-using-ode45

Commented: Talha on 20 Aug 2024 at 7:03

  • XSteam.m

Open in MATLAB Online

%% Clean the Workspace

clc

clear all

%% Format

format long

%% Variables

global m_ExtraSteam U0_shell V rho_0 U_steam

T0_shell = 105; % initial shell side temp, degC

P0_shell = 1.2; % initial pressure, bara

U0_shell = XSteam('uV_p', P0_shell);

Plimit = 3.3; % max pressure, bara

MW = 0.018015; % kg/mol

R = 0.00008205736; % bar.m3/mol.K

V = 233.21; % m3

rho_0 = XSteam('rhoV_p', P0_shell);

tb = 20; % Upper time interval limit

m_ExtraSteam = 35.08; % Flowrate of extra steam due to ST trip, kg/sec

t_interval = [0.001 tb]; % Time interval

%% Solve the DE

[tsol,Usol] = ode45(@(t, U_steam) cfunc(t, U_steam) , t_interval , U0_shell); % Temperature with time, degC

Warning: The value of local variables may have been changed to match the globals. Future versions of MATLAB will require that you declare a variable to be global before you use that variable.

Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.

Equation solved at initial point.fsolve completed because the vector of function values at the initialpoint is near zero as measured by the value of the function tolerance,and the problem appears regular as measured by the gradient.

Error using odearguments (line 94)
@(T,U_STEAM)CFUNC(T,U_STEAM) must return a column vector.

Error in ode45 (line 104)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);

%% Dynamic Parameter Calculation

Ptube_in = 7;

Ptube_out = 6.5;

m_tube = [707.9 707.9 707.9 707.9];

for m=1:lenght(Usol)

U_steam = Usol(m);

Tsol(m) = fsolve(@TfinderwU,100);

end

for p=5:length(Tsol)

T_tube_in(p) = 80.1;

m_tube(p) = 1131.2;

end

T_tube_out = 98;

for k = 1:length(Tsol)

deltaH_tube(k) = XSteam('h_pT', Ptube_out, T_tube_out) - XSteam('h_pT', Ptube_in, T_tube_in(k)); % Specific enthalpy difference between the inlet and outlet of the tube side, kJ/kg

if ((m_tube(k)*deltaH_tube(k))/(XSteam('hV_T', Tsol(k)) - XSteam('hL_T', Tsol(k)))) >= m_ExtraSteam

m_ExtraSteam_Condensation(k) = m_ExtraSteam;

else

m_ExtraSteam_Condensation(k) = (m_tube(k)*deltaH_tube(k))/(XSteam('hV_T', Tsol(k)) - XSteam('hL_T', Tsol(k)));

end

end

m_steam_accumulated = (m_ExtraSteam - m_ExtraSteam_Condensation)'; % Steam accumulated in the shell side, kg/sec

nfor(1) = m_steam_accumulated(1)*(tsol(1))/MW;

for k1 = 2:length(Tsol)

nfor(k1) = m_steam_accumulated(k1)*(tsol(k1)-tsol(k1-1))/MW;

end

%% Final Pressure Calculation

%% Plotting

figure('Name','Temperature, Pressure vs Time','NumberTitle','off');

yyaxis left % subplot(1,2,1)

plot(tsol,Tsol)

xlabel('Time (s)')

ylabel('Temperature (C)')

yyaxis right % subplot(1,2,2)

plot(tsol,Psol)

xlabel('Time (s)')

ylabel('Pressure (bara)')

%% Display Results

fprintf('Max pressure during the observed time interval = %.3f bara.\n', max(Psol))

%% Functions

% Main Function

function dUdt = cfunc(t,U_steam)

% Variables

global m_ExtraSteam U0_shell V rho_0 U_steam

Ptube_in = 7;

Ptube_out = 6.5;

T_tube_out = 98;

if t<3.3

m_tube = 707.9;

T_tube_in = 91.7;

else

m_tube = 1131.2;

T_tube_in = 80.1;

end

% Find the Temp with Internal Energy

T = fsolve(@TfinderwU,100);

deltaH_tube = XSteam('h_pT', Ptube_out, T_tube_out) - XSteam('h_pT', Ptube_in, T_tube_in); % Specific enthalpy difference between the inlet and outlet of the tube side, kJ/kg

if ((m_tube*deltaH_tube)/(XSteam('hV_T', T) - XSteam('hL_T', T))) >= m_ExtraSteam

m_ExtraSteam_Condensation = m_ExtraSteam;

else

m_ExtraSteam_Condensation = (m_tube*deltaH_tube)/(XSteam('hV_T', T) - XSteam('hL_T', T));

end

m_steam_accumulated = m_ExtraSteam - m_ExtraSteam_Condensation; % Steam accumulated in the shell side, kg/sec

steam_mass = rho_0*V + m_steam_accumulated*t;

U_condensate = XSteam('uL_T', T);

CpL = XSteam('CpL_T', T);

Qcv = m_tube*CpL*(T_tube_out-T_tube_in);

% Differential Equation

dUdt = (-Qcv + m_ExtraSteam*U0_shell - m_ExtraSteam_Condensation*U_condensate - U_steam*m_steam_accumulated)/steam_mass;

end

% Temperature Finder Function with Internal Energy

function Obj = TfinderwU(T)

global U_steam

uV_T = XSteam('uV_T', T);

Obj = U_steam- uV_T;

end

2 Comments

Show NoneHide None

Stephen23 on 20 Aug 2024 at 6:09

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2146499-must-return-a-column-vector-error-when-using-ode45#comment_3241304

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2146499-must-return-a-column-vector-error-when-using-ode45#comment_3241304

Edited: Stephen23 on 20 Aug 2024 at 6:58

Open in MATLAB Online

  • XSteam.m

dUdt is empty when the error occurs. Possible causes (that should be adressed anyway):

  • Using GLOBAL (with default = empty) instead of parameterizing the function calls: https://www.mathworks.com/help/matlab/math/parameterizing-functions.html. If a variable is used in multiple functions then use nested functions.
  • using matrix operations everywhere, a complete lack of array operations: https://www.mathworks.com/help/matlab/matlab_prog/array-vs-matrix-operations.html. This makes it unlikely that the function CFUNC was written to fulfill the requirements given in the ODE45 documentation: "The function dydt = odefun(t,y), for a scalar t and a column vector y, must return a column vector..." source: https://www.mathworks.com/help/matlab/ref/ode45.html#bu00_4l_sep_shared-odefun.

Lets test it right now:

global m_ExtraSteam U0_shell V rho_0 U_steam

T0_shell = 105; % initial shell side temp, degC

P0_shell = 1.2; % initial pressure, bara

U0_shell = XSteam('uV_p', P0_shell);

Plimit = 3.3; % max pressure, bara

MW = 0.018015; % kg/mol

R = 0.00008205736; % bar.m3/mol.K

V = 233.21; % m3

rho_0 = XSteam('rhoV_p', P0_shell);

tb = 20; % Upper time interval limit

m_ExtraSteam = 35.08; % Flowrate of extra steam due to ST trip, kg/sec

cfunc(1,[1,2]) % fails the requirements

Warning: The value of local variables may have been changed to match the globals. Future versions of MATLAB will require that you declare a variable to be global before you use that variable.

Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.

Equation solved at initial point.fsolve completed because the vector of function values at the initialpoint is near zero as measured by the value of the function tolerance,and the problem appears regular as measured by the gradient.ans = []

function dUdt = cfunc(t,U_steam)

% Variables

global m_ExtraSteam U0_shell V rho_0 U_steam

Ptube_in = 7;

Ptube_out = 6.5;

T_tube_out = 98;

if t<3.3

m_tube = 707.9;

T_tube_in = 91.7;

else

m_tube = 1131.2;

T_tube_in = 80.1;

end

% Find the Temp with Internal Energy

T = fsolve(@TfinderwU,100);

deltaH_tube = XSteam('h_pT', Ptube_out, T_tube_out) - XSteam('h_pT', Ptube_in, T_tube_in); % Specific enthalpy difference between the inlet and outlet of the tube side, kJ/kg

if ((m_tube*deltaH_tube)/(XSteam('hV_T', T) - XSteam('hL_T', T))) >= m_ExtraSteam

m_ExtraSteam_Condensation = m_ExtraSteam;

else

m_ExtraSteam_Condensation = (m_tube*deltaH_tube)/(XSteam('hV_T', T) - XSteam('hL_T', T));

end

m_steam_accumulated = m_ExtraSteam - m_ExtraSteam_Condensation; % Steam accumulated in the shell side, kg/sec

steam_mass = rho_0*V + m_steam_accumulated*t;

U_condensate = XSteam('uL_T', T);

CpL = XSteam('CpL_T', T);

Qcv = m_tube*CpL*(T_tube_out-T_tube_in);

% Differential Equation

dUdt = (-Qcv + m_ExtraSteam*U0_shell - m_ExtraSteam_Condensation*U_condensate - U_steam*m_steam_accumulated)/steam_mass;

end

% Temperature Finder Function with Internal Energy

function Obj = TfinderwU(T)

global U_steam

uV_T = XSteam('uV_T', T);

Obj = U_steam- uV_T;

end

Talha on 20 Aug 2024 at 7:03

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2146499-must-return-a-column-vector-error-when-using-ode45#comment_3241349

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2146499-must-return-a-column-vector-error-when-using-ode45#comment_3241349

Thanks. Most likely, this happens because of the global variable "U_steam" which is empty at the start.

Sign in to comment.

Sign in to answer this question.

Answers (0)

Sign in to answer this question.

See Also

Tags

  • ode45
  • function
  • error

Products

  • MATLAB

Release

R2024a

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Must return a column vector error when using "ode45" (4)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

Must return a column vector error when using "ode45" (2024)

FAQs

What is error using ode arguments must return a column vector? ›

Accepted Answer

Most commonly this error occurs when the ODE function returns a row vector rather than a column vector. If that's the case preallocate the output using zeros before filling in the elements of it or take the nonconjugate transpose of the output or reshape it or use the A(:) syntax to columnize it.

How to check if a vector is a row or column vector in matlab? ›

Direct link to this answer
  1. 'isrow' function returns true if input is row vector.
  2. 'iscolumn' function returns true if input is column vector.
  3. 'ismatrix' function returns true if input is matrix.
  4. 'isscalar' function returns true if input is scalar.
Nov 2, 2020

Can you transpose a column vector? ›

In general, the transpose of a matrix is a new matrix in which the rows and columns are interchanged. For vectors, transposing a row vector results in a column vector, and transposing a column vector results in a row vector.

What is error using cell not enough input arguments? ›

This error means that you have not provided enough input arguments to the function. You need to provide more information to the function in order to run it properly.

What does a column vector look like? ›

A column vector is simply a vector whose components are listed vertically in a single column. Doing math with column vectors is very similar to doing basic algebra. From a vector on a three-dimensional grid, the top value of the column vector is the x-component.

How do you generate a column vector? ›

One way to create a column vector is to explicitly put the values in square brackets, separated by semicolons (rather than commas or spaces): >> c = [1; 2; 3; 4] c = 1.

How do you express a column vector as a linear combination? ›

A linear combination of vectors a1 and a2 includes two steps : (1) Multiply a1 and a2 by “scalars” x1 and x2 (2) Add vectors x1a1 + x2a2. Thus Ax is a linear combination of the columns of A. This is fundamental.

How do you specify a column vector in MATLAB? ›

To create an array with multiple elements in a single row, separate the elements with either a comma ',' or a space. This type of array is called a row vector. To create an array with multiple elements in a single column, separate the elements with semicolons ';'. This type of array is called a column vector.

How to convert row vector to column vector in MATLAB? ›

You can convert a row vector into a column vector (and vice versa) using the transpose operator ' (an apostrophe). Try the following MATLAB commands: [1 3 5] is a row vector, but the ' converts it into a column vector before the result is stored in the variable x.

Is there a difference between row and column vectors? ›

A column vector is an nx1 matrix because it always has 1 column and some number of rows. A row vector is a 1xn matrix, as it has 1 row and some number of columns. This is the major difference between a column and a row vector.

Can you add a column vector and a row vector? ›

With the conventions usually in place, a 1×n 1 × n row vector is a linear functional φ:Fn→F φ : F n → F and as such, φ is belongs to the dual space of Fn . A vector and a linear functional on the vector space can't be added algebraically or geometrically because they belong to different vector spaces.

What is the difference between a vector and a transpose? ›

Vector vs.

The transpose operation means converting row to columns and vice-versa. A vector has no row or column representation, it's only a list of values.

How do you normalize a column vector? ›

In other words, to normalize a vector, simply divide each component by its magnitude. This is pretty intuitive.

What is the translation of a column vector? ›

Translations are described by column vectors: . Top number is horizontal movement: if +ve to the right if —ve to the left. Bottom number is vertical movement: if +ve up if —ve down.

How do you express vectors? ›

A vector can be described using i,j notation. A unit vector is a vector of length 1, in Cartesian co-ordinates the unit vectors along the axis are denoted by i and j respectively. Any two-dimensional vector can be written in the form ai+bj a i + b j .

Top Articles
RS3 Summoning Guide,1-99 All Methods
89074, NV Real Estate & Homes for Sale | realtor.com®
Christian McCaffrey loses fumble to open Super Bowl LVIII
Genesis Parsippany
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Repentance (2 Corinthians 7:10) – West Palm Beach church of Christ
Georgia Vehicle Registration Fees Calculator
Songkick Detroit
Roblox Developers’ Journal
Vanadium Conan Exiles
CSC error CS0006: Metadata file 'SonarAnalyzer.dll' could not be found
Heska Ulite
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Oppenheimer Showtimes Near Cinemark Denton
Pvschools Infinite Campus
Nebraska Furniture Tables
Vcuapi
272482061
Blackwolf Run Pro Shop
Soccer Zone Discount Code
Costco Great Oaks Gas Price
Aaa Saugus Ma Appointment
Caledonia - a simple love song to Scotland
Walmart Near South Lake Tahoe Ca
Reborn Rich Kissasian
8005607994
Galaxy Fold 4 im Test: Kauftipp trotz Nachfolger?
Craigslist Wilkes Barre Pa Pets
Craigslist Panama City Beach Fl Pets
Sofia the baddie dog
Bra Size Calculator & Conversion Chart: Measure Bust & Convert Sizes
27 Fantastic Things to do in Lynchburg, Virginia - Happy To Be Virginia
Martins Point Patient Portal
Pixel Combat Unblocked
Emily Katherine Correro
Beaver Saddle Ark
Lake Dunson Robertson Funeral Home Lagrange Georgia Obituary
AsROck Q1900B ITX und Ramverträglichkeit
Oxford Alabama Craigslist
Craigslist Tulsa Ok Farm And Garden
Fifty Shades Of Gray 123Movies
Academy Sports New Bern Nc Coupons
Coroner Photos Timothy Treadwell
Nami Op.gg
2024-09-13 | Iveda Solutions, Inc. Announces Reverse Stock Split to be Effective September 17, 2024; Publicly Traded Warrant Adjustment | NDAQ:IVDA | Press Release
Levi Ackerman Tattoo Ideas
Senior Houses For Sale Near Me
The Great Brian Last
Gt500 Forums
Used Sawmill For Sale - Craigslist Near Tennessee
German American Bank Owenton Ky
Latest Posts
Article information

Author: The Hon. Margery Christiansen

Last Updated:

Views: 5976

Rating: 5 / 5 (70 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: The Hon. Margery Christiansen

Birthday: 2000-07-07

Address: 5050 Breitenberg Knoll, New Robert, MI 45409

Phone: +2556892639372

Job: Investor Mining Engineer

Hobby: Sketching, Cosplaying, Glassblowing, Genealogy, Crocheting, Archery, Skateboarding

Introduction: My name is The Hon. Margery Christiansen, I am a bright, adorable, precious, inexpensive, gorgeous, comfortable, happy person who loves writing and wants to share my knowledge and understanding with you.