zlacker

[parent] [thread] 2 comments
1. henrik+(OP)[view] [source] 2020-11-30 15:40:54
Yes, the symbolic functions can be made "retroactively". The various conventional functions are overloaded with the symbolic input.

    >> syms x
    >> f = @(x) log(sqrt(x)).^2

    f = function_handle with value:

        @(x)log(sqrt(x)).^2

    >> f(x)
 
    ans = log(x^(1/2))^2
 
    >> finverse(f(x))
 
    ans = exp(2*x^(1/2))
And to implement under:

    function u = under(f, g)

    syms x

    g_inv = matlabFunction(finverse(g(x)));

    u = @(x) g_inv(f(g(x)));

    end
replies(1): >>patrec+Q3
2. patrec+Q3[view] [source] 2020-11-30 16:00:26
>>henrik+(OP)
So if you have odddouble.m with

    function y=odddouble(a,b)
       y=2*x+1
    endfunction
you can do

    >>> h = under(@(x) 1/x, odddouble)
    >>> h(3)
? If so, yeah, I agree you can implement under in matlab (as long as you have the symbolic toolbox as well); in which case it's probably one of very few non-CAS systems where you can define it.
replies(1): >>henrik+Ya2
◧◩
3. henrik+Ya2[view] [source] [discussion] 2020-12-01 07:38:33
>>patrec+Q3
Just tested it and it worked fine. Note that your function takes too many parameters in its definition and that functions can't be passed as parameters by name.

It is definitely not as elegant as the built-in facility in J, but definitely doable and usable in Matlab. In fact, I think any language with flexible enough function overloading should be able to implement such a feature.

[go to top]