Effacer les filtres
Effacer les filtres

What is wrong with my code?

1 vue (au cours des 30 derniers jours)
Eduardo Gallegos
Eduardo Gallegos le 16 Déc 2022
Commenté : Eduardo Gallegos le 16 Déc 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

Réponse acceptée

Askic V
Askic V le 16 Déc 2022
Modifié(e) : Askic V le 16 Déc 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.
  1 commentaire
Eduardo Gallegos
Eduardo Gallegos le 16 Déc 2022
Thank you, I got it fixed.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by