What is wrong with my code?

2 ビュー (過去 30 日間)
Eduardo Gallegos
Eduardo Gallegos 2022 年 12 月 16 日
コメント済み: Eduardo Gallegos 2022 年 12 月 16 日
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.
  1 件のコメント
Eduardo Gallegos
Eduardo Gallegos 2022 年 12 月 16 日
Thank you, I got it fixed.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by