필터 지우기
필터 지우기

What is wrong with my code?

조회 수: 1 (최근 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 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