Error using odearguments, mass matrix

1 visualización (últimos 30 días)
Pavel M
Pavel M el 4 de Mayo de 2019
Comentada: Walter Roberson el 7 de Mayo de 2019
Im trying to solve ODE using this
[T,Udis] = ode45(@(T,Udis) (-Udis.*v)/Eps, [0 9.99],1300)
but the error appears
Error using odearguments (line 95)
@(T,UDIS)(-UDIS.*V)/EPS returns a vector of length 1000, but the length of initial conditions vector is 1. The vector returned by @(T,UDIS)(-UDIS.*V)/EPS and the initial
conditions vector must have the same number of elements.
Udis depends on T(time), but in this function, v is a column vector (1000x1 double). Maybe, i have to use options = odeset(Name,Value,...) and specify mass matrix, but i dont understand how it works.
  3 comentarios
Pavel M
Pavel M el 5 de Mayo de 2019
No, v doesn't act as a mass matrix, i dont know how do it correctly. Also v doesn't depend on T and Udis. It is just a column vector 1000x1, which i got by calculation other function. In my mind, T is also column vector 1000x1 and each values of T and v corresponds each values of Udis. I understand that problem is v, but in help: '' Mass matrix, specified as the comma-separated pair consisting of 'Mass' and a matrix or function handle. The ODE solvers can solve problems containing a mass matrix of the form M(t,y) y′=f(t,y), where M(t,y) is a mass matrix that can be full or sparse (the ode23s solver can solve only equations with constant mass matrices). ''
I think it can solve my problem ( am i right or not?), but i i dont know how do it correctly.
Walter Roberson
Walter Roberson el 7 de Mayo de 2019
So in the option constructor you would pass
'Mass', v
If I understand correctly then this cannot solve your problem, but I might be misunderstanding so go ahead and try.
Udis is the argument for the current position, used for calculating the derivatives there. There are no particular number of them used; the ode routines use as many calls as needed to maintain accuracy. This is true even if you had passed a list of specific times to be evaluated at: the ode routines evaluate at whatever times they want and project at the times you requested. In the case where you pass in only start and end time like you do then the ode routines return a varying number of results, typically not at the times it passes in to your ode function but instead at other times to maintain accuracy.
So with you passing in exactly two times then there is no connection at all between T and length 1000.
Also in the general case, when there are multiple boundary conditions, the ode function may be evaluated multiple times with the same time but different boundary conditions, so in general you cannot expect only one call per time.
With the call you have constructed, your function will be evaluated an unknown number of times, each time with one T and one Udis value.
If you were to specify a list of 1000 times in tspan then it might be valid to use interp1 to use T to interpolate v, but that would implicitly make v a function of T.
Also possible is that you are calculating the same ide system for 1000 different v values. If that is the case then there are two different options:
1) loop doing one v at a time. If you do this then it is easiest to parameterize the ode function to pass in the current v and to pass in a list of time values to make it easier to put the results together; or
2) make your Udis a vector of length equal to length of v. If you were to do that then your existing ode function would be fine. The results would have one column for each v
Either way you would not use anything to do with a mass matrix.
There is of course another option which is to do trivial calculus. If dF/dx = -b*x then integrating both sides, F = -b/2*x^2 + c. Solve your boundary condition F(0)=1300 to get c = 1300 and you get F = -v/EPS/2 * Udis^2 + 1300 for any v.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by