Keep getting error with sample code
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Stanley Zhu
le 17 Juil 2021
Commenté : Stanley Zhu
le 17 Juil 2021
So the commented up code was the one that was provided to essentially plot my part, yet I keep getting these errors: Undefined function 'number_of_solutions' for input arguments of type'double'.
Error in Lab4 (line 68)
n = number_of_solutions(A(m), b(m));
Not sure why I'm getting these errors, are there any toolboxes or something that I'm missing. Thanks.
clear, clc, close all
syms m f
A = @(m) [m -1; (3*m-m^3) (1-3*m^2)];
b = @(m) 2*(1-m) * [1; (m^2+4*m +1)];
det(A(m));
f = matlabFunction(det(A(m)));
eqn = f(m) == 0;
solve(eqn)error wit
dx = 0.05; dy = 0.25;
for m = -2.6 : 0.2 : 2.6
n = number_of_solutions(A(m), b(m));
if f(m) == 0
zero_marker = plot(m, 0, 'bo', 'MarkerSize', 16, 'MarkerFaceColor', 'white');
else
plot(m, f(m), 'bh', 'MarkerSize', 10, 'MarkerFaceColor', 'green')
end
the_text = text(m+dx, f(m) + dy, num2str(n), 'FontSize', 24) ;
the_text.set('FontWeight', 'bold', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'bottom');
% Auto Color Code the Zero Markers and the Text
if n==0 % inconsistent! No solutions
the_text.set('Color', 'red')
% Add code to set the MarkerFaceColor for zero_marker to red.
set(zero_marker, {'MarkerFaceColor'}, get(zero_marker, 'red'));
elseif n==inf % there are free variables
the_text.set('string', '\infty')
% Add code to set the MarkerFaceColor for zero_marker to yellow.
set(zero_marker, {'MarkerFaceColor'}, get(zero_marker, 'Yellow'));
else
the_text.set('Color', 'green') % unique solution!
end
end
0 commentaires
Réponse acceptée
Cris LaPierre
le 17 Juil 2021
Modifié(e) : Cris LaPierre
le 17 Juil 2021
The issue is that number_of_solutions is not a matlab function, and your code does not create it either. The result is an error because MATLAB can't find it. Perhaps you were provided with additional code you are overlooking?
A = number_of_solutions(4,5)
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Numerical Integration and Differentiation 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!