Numerical integral with syms variables

조회 수: 46 (최근 30일)
Hossein
Hossein 2019년 9월 23일
댓글: Biyi Wang 2024년 1월 31일
Hi everybody,
I am trying to make numerical integral from a function which consists of several symbolic. It's clear that I want to make the integral with respect to a single symbolic variable (x). Can anybody help me doing this task?
many thanks in advance.
syms A B C x
f=@(x) A*x^2+B*x+C
integral(@(x) f, -1, 2)

답변 (1개)

Steven Lord
Steven Lord 2019년 9월 23일
If you had numeric values for A, B, and C then integral would be the right tool for the job. Note that nowhere in this code do I create a symbolic variable.
A = 1;
B = 2;
C = 3;
f = @(x) A*x.^2+B*x+C; % Added the period to vectorize f
result1 = integral(f, -1, 2)
I suspect you want the expression of the result to contain symbolic variables A, B, and C. If so, use int instead of integral. For this, I do need to create symbolic variables.
syms A B C x
f = A*x^2+B*x+C;
result2 = int(f, x, -1, 2)
We can confirm that result2 gives the same value as result1 when we substitute the values from the first section of code into the symbolic answer.
check = subs(result2, [A B C], [1 2 3])
  댓글 수: 6
Walter Roberson
Walter Roberson 2024년 1월 29일
The number of terms in the integration goes up as roughly (2 times size) quantity squared, and most of those terms involve division by t. The integration involves comparing each of the terms to each of the other terms, trying to figure out whether each can be used to complete the division derivative.
Biyi Wang
Biyi Wang 2024년 1월 31일
Thanks for your nice reply!
Could you please make it more clear about this following comment?
"The integration involves comparing each of the terms to each of the other terms, trying to figure out whether each can be used to complete the division derivative."

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

Community Treasure Hunt

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

Start Hunting!

Translated by