Numerical integral with syms variables

15 次查看(过去 30 天)
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