algorithm - MATLAB error using symfun/subsindex -
i'm having trouble using dsolve
symbolic functions. i'm receiving error stating:
"error using symfun/subsindex (line 121)
indexing values must 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 code stands. may seem stupid some, have relatively little experience matlab. if tell me i'm going wrong, i'd 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')
as error message states, issue line calling dsolve
. documentation indicates, function either returns either
symbolic array contains solutions of equation. size of symbolic array corresponds number of solutions.
structure array contains solutions of system of equations. number of fields in structure array corresponds number of independent variables in system.
variables solver assigns solutions of system of equations. number of output variables or symbolic arrays must equal number of independent variables in system. toolbox sorts independent variables alphabetically, , assigns solutions these variables output variables or symbolic arrays.
in other words, not return symbolic functions (symfun
). thus, matlab sees f(n)
array indexing rather symbolic function. recommend using 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, system may not have analytic solution (do have reason believe does?) because you'll warning:
warning: explicit solution not found.
and output s
empty. try applying assumptions
. (mathematica 10 doesn't fare better, it's worth.)
Comments
Post a Comment