How can I use feval, linespace and int()?

조회 수: 3 (최근 30일)
Vsevolod Kolobov
Vsevolod Kolobov 2022년 4월 2일
댓글: Vsevolod Kolobov 2022년 4월 2일
I want to calculate an indefinite integral and then draw it. A prerequisite is that the interval and the number of points are specified.
It works great:
function test
s = @(x) sin(1./x);
numPoints = 20;
xvec = linspace(0.01,0.1,numPoints);
yvec = feval(s,xvec);
plot(xvec,yvec)
end
How to do the same with the int() ?
I have tried different examples here is one of them:
function test
syms x;
ex = int(x.^2);
s = @(ex) ex;
numPoints = 20;
xvec = linspace(1,10,numPoints);
yvec = feval(s,xvec);
plot(xvec,yvec)
end
How can I use feval, linespace and int()?
  댓글 수: 1
Riccardo Scorretti
Riccardo Scorretti 2022년 4월 2일
The line s = @(ex) ex; is wrong, because you are "shading" the function ex. Basically it is the same as:
s = @(x) x;

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

채택된 답변

Riccardo Scorretti
Riccardo Scorretti 2022년 4월 2일
편집: Riccardo Scorretti 2022년 4월 2일
You can do like that:
syms x;
ex = int(x^2);
s = @(x) subs(ex, 'x', x);
numPoints = 200;
xvec = linspace(1,10,numPoints);
yvec = feval(s,xvec);
plot(xvec,yvec)
That's being said, in my opinion this is better:
syms x;
ex = int(x^2);
fplot(ex, [1 10]);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by