Why does Matlab say my function is undefined?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
So I have the following code
x=input('Enter the value x from the interval pi/6 to pi/2:');
while x<pi/6 || x>pi/2
disp(fprintf('Please enter an x value from the specified interval of pi/6 to pi/2 \n'))
x=input('Enter the value x from the interval pi/6 to pi/2:');
if x>pi/6 || x<pi/2
continue
end
end
n=input('Enter an integer for two, three, or four terms:');
while n~=2 || n~=3 || n~=4
disp(fprintf('You already entered that number or you entered an incorrect choice.\n'))
n=input('Enter an integer for two, three, or four terms:');
if n==2
y=func2(x);
Y=fprcall(x,n,y)
elseif n==3
y=func3(x);
Y=fprcall(x,n,y)
elseif n==4
y=func4(x);
Y=fprcall(x,n,y)
else
disp(fprintf('You already entered that number or you entered an incorrect choice.\n'))
end
end
function y=func2(x)
y=x-((x^3)/(factorial(3)));
end
function y=func3(x)
y=x-((x^3)/(factorial(3)))+((x^5)/(factorial(5)));
end
function y=func4(x)
y=x-((x^3)/(factorial(3)))+((x^5)/(factorial(5)))-((x^7)/(factorial(7)));
end
function Y=fprcall(x,n,y)
z=sin(x);
RE= (100*(y-sin(x)))/sin(x);
fprintf('For x=%0.4f and n=%f the values are y=%0.6f, sin(x)=%0.6f, and RE=%0.4f\n',x,n,y,z,RE)
end
For some reason when I run it for lets say when n=3, the function I have will not run. This occurs for all of them. Is there anything I am missing?
0 comentarios
Respuestas (1)
Kelly Kearney
el 27 de Nov. de 2018
If you strip out most of the commands, the main structure of your code looks like this:
n=input('Enter an integer for two, three, or four terms:');
while n~=2 || n~=3 || n~=4
% do stuff
end
So, you ask your user to enter 2, 3, or 4... but then only execute your commands if the user starts by entering an incorrect choice.
0 comentarios
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!