2

I'm having trouble using dsolve with symbolic functions. I'm receiving an error stating:

"Error using symfun/subsindex (line 121)
Indexing values must be positive integers, logicals or symbolic variables.

Error in VK3 (line 9)
[F(n), G(n), H(n)] = dsolve(diff(F) == F2, diff(G) == G2,..."

Here's my code as it stands. This may seem stupid to some, but I have relatively little experience with Matlab. If anyone could tell me where I'm going wrong, I'd be grateful.

syms F(n) G(n) H(n) F2(n) G2(n)

c = 1.004e-6;
m = input('Angular Velocity = ');
z = 0:1:20;
r = input('Radial Distance = ');
n = z*sqrt(m/c);

[F(n), G(n), H(n)] = dsolve(diff(F) == F2, diff(G) == G2,...
                            diff(F2) == F^2 - G^2 + F2*H,...
                            diff(G2) == 2*F + G2*H,...
                            diff(H) == -2*F,...
                            F(0) == 0, H(0) == 0, G(0) == 1, F(20) == 0, G(20) == 0);

U = m*r*F(n);
V = m*r*G(n);
W = sqrt(m/v)*H(n);

subplot(3,1,1)      
plot(U,n), xlabel('U'), ylabel('z'),...
           title('Radial Velocity Component')

subplot(3,1,2)      
plot(V,n), xlabel('V'), ylabel('z'),...
           title('Azimuthal Velocity Component')

subplot(3,1,3)         
plot(W,n), xlabel('W'), ylabel('z'),...
           title('Axial Velocity Component')
horchler
  • 18,384
  • 4
  • 37
  • 73
Michael
  • 21
  • 2

1 Answers1

0

As the error message states, the issue is with the line calling dsolve. As the documentation indicates, this function either returns either

  • Symbolic array that contains solutions of an equation. The size of a symbolic array corresponds to the number of the solutions.

  • Structure array that contains solutions of a system of equations. The number of fields in the structure array corresponds to the number of independent variables in a system.

  • Variables to which the solver assigns the solutions of a system of equations. The number of output variables or symbolic arrays must equal the number of independent variables in a system. The toolbox sorts independent variables alphabetically, and then assigns the solutions for these variables to output variables or symbolic arrays.

In other words, it does not return symbolic functions (symfun). Thus, Matlab sees F(n) as array indexing rather than a symbolic function. I recommend using the structure array form:

S = dsolve(diff(F) == F2,
           diff(G) == G2,...
           diff(F2) == F^2 - G^2 + F2*H,...
           diff(G2) == 2*F + G2*H,...
           diff(H) == -2*F,...
           F(0) == 0, H(0) == 0, G(0) == 1, F(20) == 0, G(20) == 0);

However, your system may not have an analytic solution (do you have reason to believe that it does?) because you'll get a warning:

Warning: Explicit solution could not be found.

and the output S will be empty. You could try applying assumptions. (Mathematica 10 doesn't fare any better, for what it's worth.)

Community
  • 1
  • 1
horchler
  • 18,384
  • 4
  • 37
  • 73