Maybe somebody will find this useful... I had the following problem. Given a hyperbolic curve
f(x)=(x^s cos(x), x^s sin(x)) for x in [0,1], find the length. The only software available on my computer was
MatLab. I was more familiar with other programs before. The main problem turned out to be how to switch from one representation of expressions to the other. The trick is to use the function
char to
produce a string representation of the expression, and then apply functions
inline (resp.
sym) to produce the inline (resp. symbolic) representation.
Let us choose
s=2.5. The solution I came up with (after searching the web for a while) was the following. There are two types of expressions in MatLab: inline and symbolic. Thus the commands (the commands in MatLab in this post will be typeset in
courier):
syms x;f=[x^2.5*cos(x) x^2.5*sin(x)];produce a symbolic expression f. One can differentiate it by
df=simplify(diff(f,x));
take the norm by
ndf=sqrt(df(1)^2+df(2)^2);and then try to integrate by say
int(ndf,x)The main problem is that the program cannot find a reasonable symbolic expression for the integral (it involves some elliptic functions). The command
quad only takes an inline expression. Thus
ndfin=vectorize(inline(char(ndf)));produces the symbolic expression
dfin for the derivative
(the
vectorize command is important for
quad - the numeric integration procedure - to work properly). Now
quad(ndfin,0,1)
produces the desired length.
I'm almost sure this is not the optimal way of doing this, but it works...
Last, but not least - if one has an inline expression g, then
gsym=sym(char(g));produces a symbolic expression gsym, which can be dealt with appropriately.