sym/subsindex error. fplot error.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to find all the numerical solutions to the equation while also plotting the function.
This is code:
syms k_f
h=4e-6;
k_0=2.*pi/10.^-6;
n_g=1.5;
n_c=1.0;
n_s=1.4;
y_s=(k_0.^2.*(n_g.^2-n_s.^2)-k_f).^0.5;
y_c=(k_0.^2.*(n_g.^2-n_c.^2)-k_f).^0.5;
k_fmax=3383598.893;
num=k_f.*((n_g.^2/n_s.^2).*y_s+(n_g.^2/n_c.^2).*y_c);
dem=k_f.^2-((n_g.^4/(n_c.^2.*n_s.^2)).*(y_c.*y_s));
G=tan(h.*k_f)==num/dem;
beta=(k_0.^2.*n_g.^2-k_f.^2).^0.5;
for h=4.*10.^-6
vpasolve(G,k_f,'Random',true)
end
%S=vpasolve(G,k_f);
P=fplot(k_f,G);
grid on
And this is the result:
>> Homework_2_4B
ans =
3.4688567555791838811284939104133e-55
Error using sym/subsindex (line 855)
Invalid indexing or function definition. Indexing must follow MATLAB
indexing. Function arguments must be symbolic variables, and function
body must be sym expression.
Error in Homework_2_4B (line 17)
P=fplot(k_f,G);
0 commentaires
Réponses (1)
Walter Roberson
le 24 Fév 2021
P=fplot(k_f,G);
G is an equation, and k_f is a plain symbolic variable.
When you fplot() you need to put an expression to be plotted first. The second (optional) parameter is the range to plot over.
fplot([lhs(G)-rhs(G),0],[-1e-60 1e-60])
I am not seeing any solutions on the plots, other than the trivial solution at 0.
1 commentaire
Walter Roberson
le 24 Fév 2021
I spoke too soon. There is an upper bound of 11448741105263.7 after which the equation goes complex valued. There do appear to be non-trivial solutions, such as near 727603.7298 . You might need to increase your digits() to compute them.
Voir également
Catégories
En savoir plus sur Conversion Between Symbolic and Numeric dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!