MATLAB Answers

Keep getting error with sample code

조회 수: 1(최근 30일)
Stanley Zhu
Stanley Zhu 2021년 7월 17일
댓글: Stanley Zhu 2021년 7월 17일
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

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 7월 17일
편집: Cris LaPierre 2021년 7월 17일
Where was this coded up? It looks like a homework assignment from Drexel University (Engr 231).
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)
Unrecognized function or variable 'number_of_solutions'.
  댓글 수: 2
Stanley Zhu
Stanley Zhu 2021년 7월 17일
Ok nevermind it seems I goofed up in terms of where I created the function folder, should've definitely had some rest cause I completely skipped over the line. Thanks.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by