Numerical integral with syms variables
18 次查看(过去 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)
0 个评论
回答(1 个)
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
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
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!