1
votes

I have a function I want to evaluate as an integral (using the function 'integral' that takes a function handle in it's arguments) that uses symbolic variables, but I want to create a matlabFunction (an anonymous function) in terms of just one of those symbolic variables, and have the others treated as constants.

s =  (g^2*t^2 + 2*sin(a)*g*t*v + v^2)^(1/2)    

S = matlabFunction(s)

S = 

@(a,g,t,v)sqrt(v.^2+g.^2.*t.^2+g.*t.*v.*sin(a).*2.0)

But what I'd like to see is

@(t)sqrt(v.^2+g.^2.*t.^2+g.*t.*v.*sin(a).*2.0)
1

1 Answers

0
votes

Here there is a workaround.

The function integral integrates numerically a function. Therefore to use it, you need a numerical expression, thus you need to give values to a, g and v.

If you dont want to do it you could symbolically integrate the equation s, so:

s =  (g^2*t^2 + 2*sin(a)*g*t*v + v^2)^(1/2)    
int(s,'t')
ans=
(t/2 + (v*sin(a))/(2*g))*(g^2*t^2 + 2*sin(a)*g*t*v + v^2)^(1/2) + (log((g^2*t^2 + 2*sin(a)*g*t*v + v^2)^(1/2) + (t*g^2 + v*sin(a)*g)/(g^2)^(1/2))*(g^2*v^2 - g^2*v^2*sin(a)^2))/(2*(g^2)^(3/2))

Then you could evaluate the integral using the Fundamental Theorem of Calculus.