MATLAB symbolic definite integration error while taking symbolic function as input arguments

조회 수: 54 (최근 30일)
The code is
syms v T;
int(@(x) x*v, 0, T)
int(@(tau) tau*v, 0, T)
I expect the answers to be T^2*v/2 but the second definite integration incorrectly contains τ.

채택된 답변

Sameer
Sameer 2024년 11월 4일 15:01
편집: Sameer 2024년 11월 4일 15:45
In the code you have provided, you are trying to perform symbolic integration using anonymous functions, which isn't directly compatible with MATLAB's "symbolic math" capabilities.
Here's a revised version of your code:
syms v T x tau;
% First integral
integrand1 = x * v;
result1 = int(integrand1, x, 0, T);
% Second integral
integrand2 = tau * v;
result2 = int(integrand2, tau, 0, T);
disp('Result of the first integral:');
disp(result1);
disp('Result of the second integral:');
disp(result2);
Hope this helps!
  댓글 수: 1
Noah Tang
Noah Tang 2024년 11월 4일 15:13
Thanks for your quick response! I now understand the difference between a symbolic function, which can be used as an input argument for the int function, and an anonymous function that involves a symbolic expression. Thanks again!

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2024년 11월 4일 18:44
syms a v T
disp(int(@(tau) tau*v, 0, T))
disp(int(@(tau) tau*a, 0, T))
Notice that in the first case, it integrated with respect to v and kept tau constant, but in the second case it integrated with respect to tau and kept a constant.
What is happening is the anonymous function is being automatically converted to a symbolic expression (not a symfun !), and then the symbolic expression is being integrated with respect to the default variable. The default variable happens to be different between [tau, v] and [tau, a]
It is arguably a bug. On the other hand, no behaviour is documented for int() of anonymous functions.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by