How to Create Vector Function File

9 vues (au cours des 30 derniers jours)
Tom Keaton
Tom Keaton le 25 Sep 2019
Modifié(e) : madhan ravi le 25 Sep 2019
Hello,
I wish to create a vector function defined as the following:
Capture.JPG
The code I have so far:
function [Ex, Ey, Ez] = E_field()
syms x y z
con = -2.8E+8;
E = con*z.^3;
Ex = matlabFunction(E(1));
Ey = matlabFunction(E(2));
Ez = matlabFunction(E(3));
end
However, I get this error when this function is being referenced when Matlab's ode solver is running:
Index exceeds the number of array elements (1).
Error in sym/subsref (line 890)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in E_field (line 7)
Ey = matlabFunction(E(2));
I do not see why this wouldn't work as I have a very similar function file that is also being referenced but doesn't throw and error:
function [Bx, By, Bz] = B_test()
%Bfieldstrength = 0.64; %In (Teslas)
magvol = 3.218E-6; %In (m)
mu0 = (4*pi)*10^-7;
magnetization = (Bfieldstrength*magvol)/mu0;
syms x y z
m = [0,0,magnetization];
r = [x, y, z];
B = mu0*(((dot(m,r)*r*3)/norm(r)^5) - m/norm(r)^3);
Bx = matlabFunction(B(1));
By = matlabFunction(B(2));
Bz = matlabFunction(B(3));
end
Suggstions?

Réponses (1)

madhan ravi
madhan ravi le 25 Sep 2019
Modifié(e) : madhan ravi le 25 Sep 2019
I don’t have any suggestions on how to improve it for as for your confusion regarding the error message:
In your first file E only have one element where as in your second file B has three elements.

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by