필터 지우기
필터 지우기

how to solve undefined variable?

조회 수: 2 (최근 30일)
SHARAD KUMAR UPADHYAY
SHARAD KUMAR UPADHYAY 2019년 8월 5일
답변: Walter Roberson 2019년 8월 6일
% I am trying to do integration with the limit x<5, as
a=any const no, for eg a= 2
f=@(x) a*x^2+sin(pi*x/2)
if x>5
output=0
else
output=integral(f,0,inf,'ArrayValued',true,'RelTol',1e-4,'AbsTol',1e-4
end
%% but error I found---- Undefined function or variable 'x'. ,if x > 5
%% please solve it
  댓글 수: 1
KSSV
KSSV 2019년 8월 5일
f=@(x) a*x^2+sin(pi*x/2)
output=integral(f,0,inf,'ArrayValued',true,'RelTol',1e-4,'AbsTol',1e-4)

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2019년 8월 6일
a=any const no, for eg a= 2
end
f=@(x) (x<5) .* (a*x^2+sin(pi*x/2));
output = integral(f,0,inf,'ArrayValued',true,'RelTol',1e-4,'AbsTol',1e-4)
Note: this might not give the right answer if f happens to be evaluated at +/- inf : there is a danger that it could return nan instead of the correct solution.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by