ode45 issue: dimension mismatch

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

ode45 issue: dimension mismatch

Tweetman
Dear all,

For my first time, I am trying to solve a differential equation using
ode45. My code looks like this:

clear; clc;
t = linspace(0,400,401);
x0 = [0, 0];
function f = dx(x,t)
M = 2.933e-5;
m = 0.158;
n = 1.26;
dx = M*x^m(1-x)^n;
endfunction
[t,x] = ode45(@dx, t, x0);

The error I get is a dimension mismatch and I do not understand a
mismatch between which parameters.

Can this function be solved by ode45 at all or should I use a different
solver or bring the function to a different form? If so, which? I
appreciate any kind of information.

Thanks,
Jan


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: ode45 issue: dimension mismatch

Carlo de Falco-2
Hi,

> On 6 Feb 2018, at 12:07, Tweety <[hidden email]> wrote:
>
> Dear all,
>
> For my first time, I am trying to solve a differential equation using
> ode45. My code looks like this:
>
> clear; clc;
> t = linspace(0,400,401);
> x0 = [0, 0];
> function f = dx(x,t)
> M = 2.933e-5;
> m = 0.158;
> n = 1.26;
> dx = M*x^m(1-x)^n;
> endfunction
> [t,x] = ode45(@dx, t, x0);
>
> The error I get is a dimension mismatch and I do not understand a
> mismatch between which parameters.
>
> Can this function be solved by ode45 at all or should I use a different
> solver or bring the function to a different form? If so, which? I
> appreciate any kind of information.

There are so many errors in the few lines of code above that it is quite
difficult to understand what actually is the proble that you are trying to
solve, maybe it would be easier to understand what you are trying to accomplish
if you write in formulas rather than in code.

Is this some sort of homework?

We usually don't solve homework questions on this list, but we do answer specific
questions about the usage of octave functions.

> Thanks,
> Jan

c.




-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: ode45 issue: dimension mismatch

Tweetman
Hi, Thanks for the reply. Basically, the equation I am trying to solve is

dx/dt = M*x^m (1-x)^n

The equation describes the reaction kinetics of a specific polymer over
time. M=2.93e-5 is a pre factor, m=0.158 and n=1.26 are exponents which
describe the order of the two parts of a reaction.

I wish it was homework so I could actually speak to others having the
same issue... no.

Kind regards,
Jan

Am 06.02.2018 um 15:52 schrieb Carlo De Falco:

> Hi,
>
>> On 6 Feb 2018, at 12:07, Tweety <[hidden email]> wrote:
>>
>> Dear all,
>>
>> For my first time, I am trying to solve a differential equation using
>> ode45. My code looks like this:
>>
>> clear; clc;
>> t = linspace(0,400,401);
>> x0 = [0, 0];
>> function f = dx(x,t)
>> M = 2.933e-5;
>> m = 0.158;
>> n = 1.26;
>> dx = M*x^m(1-x)^n;
>> endfunction
>> [t,x] = ode45(@dx, t, x0);
>>
>> The error I get is a dimension mismatch and I do not understand a
>> mismatch between which parameters.
>>
>> Can this function be solved by ode45 at all or should I use a different
>> solver or bring the function to a different form? If so, which? I
>> appreciate any kind of information.
>
> There are so many errors in the few lines of code above that it is quite
> difficult to understand what actually is the proble that you are trying to
> solve, maybe it would be easier to understand what you are trying to accomplish
> if you write in formulas rather than in code.
>
> Is this some sort of homework?
>
> We usually don't solve homework questions on this list, but we do answer specific
> questions about the usage of octave functions.
>
>> Thanks,
>> Jan
>
> c.
>
>


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: ode45 issue: dimension mismatch

Sergei Steshenko



From: Tweety <[hidden email]>
To: Carlo De Falco <[hidden email]>
Cc: "[hidden email]" <[hidden email]>
Sent: Tuesday, February 6, 2018 5:13 PM
Subject: Re: ode45 issue: dimension mismatch

Hi, Thanks for the reply. Basically, the equation I am trying to solve is

dx/dt = M*x^m (1-x)^n

The equation describes the reaction kinetics of a specific polymer over
time. M=2.93e-5 is a pre factor, m=0.158 and n=1.26 are exponents which
describe the order of the two parts of a reaction.

I wish it was homework so I could actually speak to others having the
same issue... no.

Kind regards,
Jan

Am 06.02.2018 um 15:52 schrieb Carlo De Falco:

> Hi,
>
>> On 6 Feb 2018, at 12:07, Tweety <[hidden email]> wrote:
>>
>> Dear all,
>>
>> For my first time, I am trying to solve a differential equation using
>> ode45. My code looks like this:
>>
>> clear; clc;
>> t = linspace(0,400,401);
>> x0 = [0, 0];
>> function f = dx(x,t)
>> M = 2.933e-5;
>> m = 0.158;
>> n = 1.26;
>> dx = M*x^m(1-x)^n;
>> endfunction
>> [t,x] = ode45(@dx, t, x0);
>>
>> The error I get is a dimension mismatch and I do not understand a
>> mismatch between which parameters.
>>
>> Can this function be solved by ode45 at all or should I use a different
>> solver or bring the function to a different form? If so, which? I
>> appreciate any kind of information.
>
> There are so many errors in the few lines of code above that it is quite
> difficult to understand what actually is the proble that you are trying to
> solve, maybe it would be easier to understand what you are trying to accomplish
> if you write in formulas rather than in code.
>
> Is this some sort of homework?
>
> We usually don't solve homework questions on this list, but we do answer specific
> questions about the usage of octave functions.
>
>> Thanks,
>> Jan
>
> c.
>
>


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------

On the surface, purely mathematically,

dx = M*x^m(1-x)^n;

looks wrong.

You probably meant

dx = M*x^m * (1-x)^n;
.

I've added '*' op sign between 'm'  and the following '('. As a general rule of thumb surround op signs with spaces. I.e. do not write

a+b

, rather write

a + b
.

I.e. judging by your reply I presume 'm' is constant - not a function. The original "m(1-x)" - looks like a function call or like extraction of component with index of 1-x from vector m.

--Sergei.




-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: ode45 issue: dimension mismatch

Svetlana Tkachenko-2
I am having difficulty parsing `dx = M*x^m(1-x)^n;`. What does it mean? I'd add more brackets for clarity.


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: ode45 issue: dimension mismatch

Thomas D. Dean-2
On 02/06/18 21:15, Svetlana Tkachenko wrote:
> I am having difficulty parsing `dx = M*x^m(1-x)^n;`. What does it mean? I'd add more brackets for clarity.
>

As stated before,  m(1-x) can mean either a function call or the 1-x th
element of m.

I believe you want m*(1-x).

Look at 'help function'

Tom Dean


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: ode45 issue: dimension mismatch

Tweetman
In reply to this post by Svetlana Tkachenko-2
Hello, sorry for the confusion. Yes, what I meant was

dx/dt = M*(x^m)*(1-x)^n

From my original post it became clear that M, m and n are constants.
When I let octave run on below code, I now get

warning: dx: some elements of return values are undefined.
error: ode45 [...] dimension mismatch

Still do not understand, t has been defined globally and in my thinking
x is supposed to be the outcome of ode45? If I define x = zeros(101,1)
within the function as seen in some examples on the internet, I get a
message on nonconformant arguments (op1 is 101x1, op2 is 101,1).

The dimensions of which variables must match?

Thanks,
Jan

clear; clc;
t = linspace(0,400,101);
x0 = [0, 0];
function f = dx(x,t)
M = 2.933e-5;
m = 0.158;
n = 1.26;
dx = M*(x.^m)*(1-x).^n;
endfunction
[t,x] = ode45(@dx, t, x0);

Am 07.02.2018 um 06:15 schrieb Svetlana Tkachenko:
> I am having difficulty parsing `dx = M*x^m(1-x)^n;`. What does it mean? I'd add more brackets for clarity.
>


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: ode45 issue: dimension mismatch

Sebastian Schöps
Tweetman wrote
> Hello, sorry for the confusion. Yes, what I meant was
> dx/dt = M*(x^m)*(1-x)^n

If the initial value is x(0)=0 then your ODE will only have the trivial
solution x=0.


Tweetman wrote

> clear; clc;
> t = linspace(0,400,101);
> x0 = [0, 0];
> function f = dx(x,t)
> M = 2.933e-5;
> m = 0.158;
> n = 1.26;
> dx = M*(x.^m)*(1-x).^n;
> endfunction
> [t,x] = ode45(@dx, t, x0);

* I suggest to use a anonymous function, see
https://www.gnu.org/software/octave/doc/v4.2.0/Anonymous-Functions.html
* Your initial value as two components but it is a scalar ode

Try this:

t = linspace(0,400,101);
x0 = 0;
M = 2.933e-5;
m = 0.158;
n = 1.26;
dx = @(t,x) ( M*(x.^m)*(1-x).^n );
[t,x] = ode45(dx, t, x0);
plot(t,x)

and enjoy the zero function :)

Seb.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: ode45 issue: dimension mismatch

Carlo de Falco-2
In reply to this post by Tweetman


> On 7 Feb 2018, at 08:22, Tweety <[hidden email]> wrote:
>
> x0 = [0, 0];

from what I gathered from the previous discussion, your unknown x is a scalar, so your initial value should be a scalar too.
c.




-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: ode45 issue: dimension mismatch

gciriani
If you read the documentation for ODE45, t has to be a column vector. You
have instead supplied a row vector. Try with t =
transpose(linspace(0,400,401));



-----
Giovanni Ciriani - Windows 10, Octave 4.2.1, configured for x86_64-w64-mingw32
--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Giovanni Ciriani - Windows 10, Octave 4.2.1, configured for x86_64-w64-mingw32