solving an integral to get a numerical answer

12 visualizaciones (últimos 30 días)
Mister Tea
Mister Tea el 23 de Dic. de 2018
Comentada: Walter Roberson el 23 de Dic. de 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.
  1 comentario
Mister Tea
Mister Tea el 23 de Dic. de 2018
sorry corrected some errors in the posted code and result.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 23 de Dic. de 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 comentarios
Star Strider
Star Strider el 23 de Dic. de 2018
It is not, unless you specify it as an argument to the function.
Walter Roberson
Walter Roberson el 23 de Dic. de 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))

Iniciar sesión para comentar.

Más respuestas (1)

Mister Tea
Mister Tea el 23 de Dic. de 2018
Editada: Mister Tea el 23 de Dic. de 2018
syms x Variable
y(Variable) = 2*x * Variable;
Integral(Variable) = int(y,x,0,pi)
Output:
Integral(Variable) =
Variable*pi^2
integrating the function y with respect to x without calling it in the argument.
I will go do other things now, thank you for your first answer

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by