system of ode plotting solution

2 visualizzazioni (ultimi 30 giorni)
Shubham
Shubham il 19 Feb 2021
Commentato: Shubham il 20 Feb 2021
function qdot = vdPav(t,q)
Delta= -2;
F= 1;
epsilon = 0.1;
qdot = [epsilon((1/2)*q(1)-(1/8)*q(1)^3+(1/2)*Delta*q(2)-(1/8)*q(1)*q(2)^2-(1/2)*F);epsilon((1/2)*q(2)-(1/8)*q(2)^3+(1/2)*Delta*q(1)-(1/8)*q(2)*q(1)^2)];
op = odeset('relTol',1e-7,'abstol',1e-7);
[t,q] = ode15s('vdPav',[0 50],[0.1 0.1],op);
plot(q(:,1),q(:,2));
I am trying to plot q(1) v/s q(2) but I am getting error
  5 Commenti
Walter Roberson
Walter Roberson il 19 Feb 2021
qdot = [epsilon((1/2)*q(1)-(1/8)*q(1)^3+(1/2)*Delta*q(2)-(1/8)*q(1)*q(2)^2-(1/2)*F);epsilon((1/2)*q(2)-(1/8)*q(2)^3+(1/2)*Delta*q(1)-(1/8)*q(2)*q(1)^2)];
^ ^
I have marked the two places for you. In two places you have epsilon immediately followed by ( . In MATLAB, when you have a name immediately followed by a ( then there are only five possibilities:
  1. That the name is a variable that designates a function handle, and what is inside the () is a list of parameters to pass to the function
  2. That the name is a variable that designates an array, and the expression inside the () is an index or list of indices into the array
  3. That the name is a method of an object whose type dominates the list of expressions inside the (), and the method is to be called passing in the list of parameters
  4. That the name is a function found somewhere in the calling hierarchy or MATLAB path, and what is inside the () is a list of parameters to pass to the function
  5. That none of the above hold and the situation is an error (including, here, the case where the name is a valid function that does not happen to be along the MATLAB path
The situation you are encountering is the second of those, where epsilon is a numeric array. As such, what is inside the () must be either a logical array of any size, or else an expression that evalutes to an empty numeric array, or else an expression that evaluates to an array of positive integers of any size.
But in your situation, with the 1/2's and 1/8's and so on, what is inside the () does not happen to evaluate to an array of positive integers, and so cannot be used to index the array epsilon
What Kalyan and I speculate is that what you wanted was to multiply epsilon by the expression. But MATLAB does not implied multiplication anywhere -- not even inside the details of the hidden internal symbolic programming language. NONE. In every case, if you want to indicate multiplication, you need to use either the .* or * operator. The .* operator is element-by-element multiplication. The * operator is algebraic matrix multiplication (inner product). When you are multiplying a scalar by something then you can use either operator, but I recommend that you get in the habit of using .* unless you specifically intend inner product.
Shubham
Shubham il 20 Feb 2021
Yes I rectified my mistake thanks a lot

Accedi per commentare.

Risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by