What is wrong with my code?

1 次查看(过去 30 天)
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

采纳的回答

Askic V
Askic V 2022-12-16
编辑:Askic V 2022-12-16
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by