What is wrong with my code?

2 views (last 30 days)
Eduardo Gallegos
Eduardo Gallegos on 16 Dec 2022
Commented: Eduardo Gallegos on 16 Dec 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

Accepted Answer

Askic V
Askic V on 16 Dec 2022
Edited: Askic V on 16 Dec 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.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!