Filter löschen
Filter löschen

how to solve undefined variable?

2 Ansichten (letzte 30 Tage)
SHARAD KUMAR UPADHYAY
SHARAD KUMAR UPADHYAY am 5 Aug. 2019
Beantwortet: Walter Roberson am 6 Aug. 2019
% 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 Kommentar
KSSV
KSSV am 5 Aug. 2019
f=@(x) a*x^2+sin(pi*x/2)
output=integral(f,0,inf,'ArrayValued',true,'RelTol',1e-4,'AbsTol',1e-4)

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 6 Aug. 2019
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.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by