Uzair Khan
Uzair Khan

Reputation: 15

MATLAB not evaluating integral

MATLAB gives me the same expression back. Here's my code

syms tau alpha phi
f = sign(alpha*cos(phi))*(abs(alpha*cos(phi)) - 2.5*(alpha*cos(phi))^2);
F=f*sin(phi);
int(F,phi, [pi/2, acos(tau/alpha)])

I did plug in the values of variables tau and alpha but it still gives me the same expression back. Anyone know how to solve it? Or some other numerical method which could give me answer in these symbols? Will wolfram-mathematica help?

Upvotes: 0

Views: 175

Answers (2)

Bill
Bill

Reputation: 3977

Mathematica

Integrate[(Sign[alpha*Cos[phi]]*(Abs[alpha*Cos[phi]] - 5/2*
  (alpha*Cos[phi])^2))*Sin[phi], {phi, Pi/2, ArcCos[tau/alpha]}]

(* ConditionalExpression[-(tau^2/(2 alpha)) + (5 alpha^3 Abs[tau]^3)/ (6 Abs[alpha]^4), ArcCos[tau/alpha] \[Element] Reals] *)

Thus the result is the expression inside the ConditionalExpression if the ArcCos[tau/alpha] is an element of the reals.

If you could specify something like -1<=tau/alpha<=1 && 0<=tau then it can provide an even simpler result, (tau^2 (-3 + 5 tau))/(6 alpha)

Please verify this before you depend on it.

Upvotes: 0

Leander Moesinger
Leander Moesinger

Reputation: 2462

Something like

syms tau alpha phi
f = sign(alpha*cos(phi))*(abs(alpha*cos(phi)) - 2.5*(alpha*cos(phi))^2);

will just generate another symbolic variable. Your goal however is to specify a symbolic function and for that you have to specify the function arguments:

syms tau alpha phi
f(tau,alpha,phi) = sign(alpha*cos(phi))*(abs(alpha*cos(phi)) - 2.5*(alpha*cos(phi))^2);
F(tau,alpha,phi) =f*sin(phi);

Then you can calculate the integral with

R = int(F,phi, [pi/2, acos(tau/alpha)])

Since your integral is dependent on tau and alpha, R is again a symbolic function R(tau,alpha).

Alternatively you could just specify the arguments at the end, e.g.

syms tau alpha phi
f = sign(alpha*cos(phi))*(abs(alpha*cos(phi)) - 2.5*(alpha*cos(phi))^2);
F=f*sin(phi);
R(tau,alpha) = int(F,phi, [pi/2, acos(tau/alpha)])

But I personally find that less clean.

Note that you could also write F directly as

F(tau,alpha,phi) = sin(phi)*(sign(alpha*cos(phi))*(abs(alpha*cos(phi)) - 2.5*(alpha*cos(phi))^2));

Upvotes: 0

Related Questions