Error using odearguments

What does this error message mean? ??? Error using ==> odearguments at 120 Inputs must be floats, namely single or double. Error in ==> ode45 at 172 [neq, tspan, ntspan, next, t0,...

Richard

What does this error message mean?

??? Error using ==> odearguments at 120

Inputs must be floats, namely single or double.

Error in ==> ode45 at 172

[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn,

Error in ==> Testfunction at 32

[t,x] = ode45(@somefn, tspan, x0);

Thanks in advance for any help!

Accepted Answer

Jan

The message means, that the subfunction odearguments recieves non-float values, although it needs this type. The message is actually clear in this point.

Are tspan or x0 both floating point types? You can check this by:


More Answers (3)

shobhit kumar

i have the same problem but when i check class of x0 and tspan it is double than why i got the same error


Makkena

[tOut, XOut] =ode45@ballTrajectoryFun,tSpan,X,[],param);

plot(xOut(:,1),xout(:,2),‘bo’);

xlabel(‘x(m)’); ylabel(‘y(m)’);

exitcode = ballAnimation(tOut,xOut)


Makkena

fuction I =trap(func,a,b,n,varargin)

% trap: composite trapezoidal rule quadrature

% I = trap(func,a,b,n,p1,p2,….):

% composite trapezoidal rule

% input:

% func =function handle to function to be integrated

% a,b = integration limits

% n = number of segments (defult = 100)

% p1,p2,….= additional parameters used by func

% output:

% I = intergal estimate

if nargin<3,error(‘at least 3 inputs arguments requried’),end

if~(b>a),error(‘upper bound must be greater than lover’)

if nargin<4||isempty(n),n=100;end

x = a;h = (b — a)/n;

s=func(a,varargin(:));

for i = 1: n-1

x = x + h;

s = s +2*func(x,varagin(:));

end

s = s + func(b,varagin(:));

I = (b-a) *s/(2*n);

SNOP. 

 Re: Матлаб, решение системы линейных диффуров

Сообщение10.05.2016, 19:03 


26/04/16
11

У меня все работает.

global T E U11 U22 U21 U12 G T0 X0 A
T = 1
E = 2
U11 = 3
U22 = 4
U12 = 5
U21 = 6
G = 7
T0 = [0 1]
X0=[1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0];
A = [0*1i, 0, T, -T, 0, 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 0, 0, 0, T, 0, U22-U12-3*G*1i-E, T, 0, 0, -T, 0, 0, 0, -T, 0, 0, 0, 0, 0, 0, 0, 0, U21-U22, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, T, T, —2*G*1i, 0, 0, 0, -T, 0, 0, 0, -T, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, U21-E-U11-G*1i, T, T, 0, 0, 0, 0, 0, -T, 0, 0, 0, 0, 0, U12-U22, 0, 0, 0, 0, 0
    0*1i, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, T, 0, 0, T, 0, 0, 0, 0, 0, -T, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, T, 0, —2*G*1i, T, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, 0, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, T, T U21-U11-E-G*1i, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, U22-U12, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, 0, 0, 0, 0, E+U12-U22-3*G*1i, T, T, 0, -T, 0, 0, 0, 0, U11-U21, 0, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, 0, 0, 0, T, 2*(E+U11-U21-G*1i), 0, T, 0, -T, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, 0, 0, T, 0, —4*G*1i, T, 0, 0, -T, 0, 0, 0, 0, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, 0, 0, T, T, E+U12-U22-3*G*1i, 0, 0, 0, -T, U11-U21, 0, 0, 0, 0, 0, 0,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0, 0, 0, 0, 0, 0, 0, 0, T, 0, -T, 0, —4*G*1i, 0, 0
    0*1i, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, T, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, T, 0, -T, 0, 0, 0, 0, —4*G*1i];

function dX=func1(t, X)
global T E U11 U22 U21 U12 G T0 X0 A
dX=A*X;
end

ode45(@func1, T0, X0)

Да, заработало, возможно end не хватало. А не подскажете, как теперь построить только X(1)? Писать отдельную m-функцию или можно сразу после ode писать?

— 10.05.2016, 19:15 —

Решил разделить на две части:
Функцию:

function dX=func2(t, X)
global T E U11 U22 U21 U12 G T0 X0 A
dX=A*X;
end

И Решение как-то так:

T=1; E=0.21; U11=0;U21=0;U12=0;U22=0; G=0.001; T0=[0,1];
X0=[1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0];
A = [0*1i, 0, T, -T, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    0, —2*G*1i, -T, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    T, -T, -E-G*1i, 0, 0, 0, 0, 0, 0, 0, 0, 0, U21-U11, 0, 0, 0, 0, 0, 0, 0, 0, 0, U22-U12, 0, 0, 0, 0, 0, 0, 0, 0, 0
    -T, T, 0, E-G*1i, 0, 0, 0, 0, 0, U11-U21, 0, 0, 0, 0, 0, 0, 0, 0, 0, U21-U22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    0*1i, 0, 0, 0, 0, 0, T, -T, 0, 0, 0, 0, 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T, 0, —2*G*1i, T, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, 0, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, T, T U21-U11-E-G*1i, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, U22-U12, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, 0, 0, 0, 0, E+U12-U22-3*G*1i, T, T, 0, -T, 0, 0, 0, 0, U11-U21, 0, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, 0, 0, 0, T, 2*(E+U11-U21-G*1i), 0, T, 0, -T, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, 0, 0, T, 0, —4*G*1i, T, 0, 0, -T, 0, 0, 0, 0, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, 0, 0, T, T, E+U12-U22-3*G*1i, 0, 0, 0, -T, U11-U21, 0, 0, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, -T, 0, 0, 0, —2*G*1i, T, T, 0, 0, 0, 0, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, -T, 0, 0, T E+U11-U21-G*1i, 0, T, 0, U12-U22, 0, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, -T, 0, T, 0, -E+U22-U12-3*G*1i, 0, 0, 0, U21-U11, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, 0, 0, -T, 0, T, T, —2*G*1i, 0, 0, 0, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, E+U11+U12-U21-U22-3*G*1i, 0, 0, 0, 0, 0, -T, T
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, E+U11+U12-U21-U22-3*G*1i, 0, 0, -T, T, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, T+U21+U12-E-U11-U22-3*G*1i, 0, 0, 0, T, -T
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, U11+U22-U12-U21-E-3*G*1i, T, -T, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, T, —2*G*1i, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, T, 0, -T, 0, —4*G*1i, 0, 0
    0*1i, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -T, 0, T, 0, 0, 0, 0, 0
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, T, 0, -T, 0, 0, 0, 0, —4*G*1i];

ode45(@func2, T0, X0);
plot(T,X(:,1),‘x’);
grid on
xlabel(‘t’);

В результате получаю:
Error using odeplot (line 63)
Error updating the ODEPLOT window. Solution data may have been corrupted. Argument Y cannot be complex.

Error in ode45 (line 435)
stop = feval(outputFcn,tout_new,yout_new(outputs,:),»,outputArgs{:});

Error in reshenie (line 36)
ode45(@func2, T0, X0);
Что за хрень?

— 10.05.2016, 19:20 —

Можно ли сделать так, чтобы строилась только действительная часть, то есть чтобы он считал все полностью, но строил только действительную часть?

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.
  • Forums

  • Mathematics

  • MATLAB, Maple, Mathematica, LaTeX

A Lorenz’s system of ODEs doesn’t get executed in Matlab

  • MATLAB

  • Thread starter
    MathematicalPhysicist

  • Start date
    Apr 16, 2020

  • Apr 16, 2020
  • #1
I use the following script and function in MatLab, but get three errors.
I shall first write down the code and after that the errors that I get.

function yprime = lorenz_de(t,y)
%LORENZ_DE    Lorenz equations.
%   yprime  = lorenz_de(t,y).

yprime = [10*(y(2)-y(1))
          28*y(1)-y(2)-y(1)*y(3)
          y(1)*y(2)-8*y(3)/3];

%LORENZ_RUN     ODE solving example: Lorenz.

tspan = [0 50];                       % Solve for 0 <= t <= 50.
yzero = [0;1;0];                      % Initial conditions.
[t,y] = ode45(@lorenz_de,tspan,yzero);
plot(y(:,1),y(:,3))                   % (y_1,y_3) phase plane.
xlabel('y_1','FontSize',14)
ylabel('y_3 ','FontSize',14,'Rotation',0,'HorizontalAlignment','right')
title('Lorenz equations','FontSize',16,'FontWeight','normal')

Here are the errors:

Error using odearguments (line 93)
LORENZ_DE must return a column vector.

Error in ode45 (line 115)
  odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

Error in lorenz_run (line 5)
[t,y] = ode45(@lorenz_de,tspan,yzero);

How to fix these errors?
Thanks!

Answers and Replies

  • Apr 16, 2020
  • #2
Works perfectly fine for me:

1587099581273.png

  • Apr 17, 2020
  • #3
@Orodruin thanks for replying.

It seems something is wrong with my software, can you give a look at the errors I listed in my OP?
BTW which version of MatLab are you using?

I am using 2018b, and now I am downloading update 2.

  • Apr 17, 2020
  • #4
I have a rather old version of Matlab, 2014b if I recall correctly …

The errors suggest that your lorenz_de function does not return a column vector, but it does. The only thing I can think about is if your main file and lorenz_de are located in different folders and you have an old copy of lorenz_de lying around in the same folder as the main file.

  • Apr 17, 2020
  • #5
@MathematicalPhysicist Your code works fine in my 2019b.

One thing that you can try is to convert the function into an inner function in the script. This way, the script will only refer to the function within the script and you can avoid the the duplicate files issue stated by @Orodruin in #4.

Another option is to completely convert the script into a function. Let the inner (nested) function remain as it is. This way, there will be no collision with workspace variables, if any.

Last edited: Apr 17, 2020

  • Apr 17, 2020
  • #6
It works!

Sing Halleluja!
It seems I should have saved the two files in the directory of MatLab and then make the directory into the add to path.
[youtube]

Suggested for: A Lorenz’s system of ODEs doesn’t get executed in Matlab

  • Last Post
  • Jan 28, 2023
  • Last Post
  • Jul 2, 2021
  • Last Post
  • Jul 12, 2021
  • Last Post
  • Apr 26, 2021
  • Last Post
  • Jan 24, 2023
  • Last Post
  • Apr 21, 2022
  • Last Post
  • Aug 10, 2019
  • Last Post
  • Oct 29, 2022
  • Last Post
  • Jan 7, 2023
  • Last Post
  • Jun 10, 2021
  • Forums

  • Mathematics

  • MATLAB, Maple, Mathematica, LaTeX

Понравилась статья? Поделить с друзьями:
  • Error unmappable character for encoding cp1252
  • Error unknown procedure parent 2 dwim could not correct goal
  • Error unexpected mutation of prop vue no mutating props
  • Error unexpected end of file radmir
  • Error uncaught rangeerror webassembly memory could not allocate memory