solving an integral to get a numerical answer
13 views (last 30 days)
Show older comments
Mister Tea
on 23 Dec 2018
Commented: Walter Roberson
on 23 Dec 2018
I am struggling to solve an integral and get a definite numerical answer from it in Matlab
Here is the code that I am using:
syms r C z x I u_0
k(r,C,z) = (2*sqrt(r*C))/(sqrt(r+C)^2+z^2);
fun_K(r,C,z) = 1/(sqrt(1-k^2*sin(x)^2)); % function K
K(r,C,z) = int(fun_K,x,0,pi/2); % integral of function K
fun_E(r,C,z) = sqrt(1-k^2*sin(x)^2); % function E
E(r,C,z) = int(fun_E,x,0,pi/2); % integral of function E
% print out result
r = 0.004; C = 0.025; z = 0.03;
K(r,C,z)
E(r,C,z)
From this, I get the elliptics:
K(r,C,z) = ellipticK(40000/89401)
E(r,C,z) =ellipticE(40000/89401)
Is it possible to get a numeric answer from this to then use later in calculation or am I doing something fundamentally wrong here?
Thanks in advance.
Accepted Answer
Star Strider
on 23 Dec 2018
First, you can probably use the double function, or the vpa function first, then double.
Second, your code throws this error:
Undefined function or variable 'x'.
fun_K(r,C,z) = 1/(sqrt(1-k^2*sin(x)^2)); % function K
When I try to run what you’ve posted.
I could be of more help if you correct that, since neither MATLAB nor I know what ‘x’ refers to here.
10 Comments
Walter Roberson
on 23 Dec 2018
Star Strider:
When you use a symbolic function such as fun_K as the argument, and you specify a symbolic variable to integrate with respect to, then int() will integrate with respect to that variable, even if it is not an argument to the function. The effect is as-if you had called the function with the symbolic variables that are the arguments to the function, giving a symbolic expression, which is then integrated with respect to the variable that you specified for integration, and the result is then symfun() with respect to the inputs to the symbolic function.
>> syms r C z x I u_0
k(r,C,z) = (2*sqrt(r*C))/(sqrt(r+C)^2+z^2);
fun_K(r,C,z) = 1/(sqrt(1-k^2*sin(x)^2)); % function K
>> int(fun_K,x,0,pi/2)
ans(r, C, z) =
piecewise(z^2 + C + r ~= 0, ellipticK((4*C*r)/(C + r + z^2)^2))
>> fun_K(r,C,z)
ans =
1/(1 - (4*C*r*sin(x)^2)/(z^2 + C + r)^2)^(1/2)
>> int(fun_K(r,C,z),x,0,pi/2)
ans =
piecewise(z^2 + C + r ~= 0, ellipticK((4*C*r)/(C + r + z^2)^2))
More Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!