What is wrong with my code?
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Eduardo Gallegos
 el 16 de Dic. de 2022
  
    
    
    
    
    Comentada: Eduardo Gallegos
 el 16 de Dic. de 2022
            Hi everyone I don't know how to fix this code. I don't what's wrong
Function below this sentence.
function [y] = fcn1(x)
 total = 0;
  term = zeros(1, 100);
  for k = 1:100
      term(k) = pi/(12+ k^b);
      total = total + term(k);
      if (term(k) < loop_limit) 
          break
      end
  end
end
Function Call below this sentence
clc; close all; clear all
b = 3; 
loop_limit = 0.001
y =fcn1(3)
Error message below this sentence.
Unrecognized function or variable 'b'.
Error in fcn1 (line 5)
      term(k) = pi/(12+ k^b);
Error in fcn1call (line 4)
y =fcn1(3)
Any input would be greatly appreciated
0 comentarios
Respuesta aceptada
  Askic V
      
 el 16 de Dic. de 2022
        
      Editada: Askic V
      
 el 16 de Dic. de 2022
  
      In the line inside the function:
term(k) = pi/(12+ k^b);
but you didn't send b as an input parameter nor did you define it inside the function.
The same is for variable loop_limit. They exist in totaly different memory space comparing to the function.
Más respuestas (0)
Ver también
Categorías
				Más información sobre Loops and Conditional Statements 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!

