[Scilab-users] Nested function definition

Izabela Wójcik-Grząba iwoj at il.pw.edu.pl
Wed Apr 10 16:04:04 CEST 2019


Ok, so why nested function in help is so complicated:

//nested functions definition
function y=foo(x)
    a=sin(x)
    function y=sq(x), y=x^2,endfunction
    y=sq(a)+1
endfunction

foo(%pi/3)

Couldn't it be formulated like below:

function y1=foo1(x)
    a=sin(x);
    y1=a^2+1;
endfunction

foo1(%pi/3)

That's why I had problems with my functions and couldn't understand why 
it has to be so complicated.

Thank you once more.

Iza




W dniu 10.04.2019 14:10, Rafael Guerra napisał(a):
> In your example, why not using a simpler URQ function definition into 
> fsolve?
> For example:
> 
> mg = 0.1; h=0.1; l=0.1; L0=0.1;
> function y=URQ(q)
>     e = mg./(2*q);
>     z= asinh(mg.*h./(2*q.*l.*sinh(e)))+e;
>     y= mg.*L0./(q.*l)-sinh(2*e-z)-sinh(z)
> endfunction
> 
> q=1;
> y=URQ(q)
> 
> Rgds
> Rafael
> 
> -----Original Message-----
> From: users <users-bounces at lists.scilab.org> On Behalf Of Izabela 
> Wójcik-Grzaba
> Sent: Wednesday, April 10, 2019 3:01 PM
> To: Users mailing list for Scilab <users at lists.scilab.org>
> Subject: Re: [Scilab-users] Nested function definition
> 
> Thank you. Is there a way to use this formulation as an input function
> to fsolve? I don't know how to do it.
> 
> In my another example I also had a nested function but I managed to
> define it in a form like in help page about function. It means that
> everything was inside one function. This formulation worked fine in
> fsolve, but with my current example I am not able to use it.
> 
> Iza
> 
> 
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users



More information about the users mailing list