[Scilab-users] qustion on functional argument

roger.cormier at ncf.ca roger.cormier at ncf.ca
Tue Apr 21 01:09:22 CEST 2015


Let me understand correctly. You have two conditions, namely when x>1, and when x<=1. For x1, you want an element-by-element 1/x, not a matrix inversion of x.

For element-by-element division, I would use:

b=1 ./x

Note the space between "1" and the period "." because "1" is a number not a variable. Look in the help section under "division". It will explain the "/" and how to manipulate it to get what you want to achieve.

Regards,




___________________________
Dr. Roger Cormier, P.Eng.
Home Tel. & Fax: 613-823-7299


Le dim. 19 avr. 2015 à 11:57, fujimoto2005 a écrit :

> I define a function with a scalar argument and use it with a matrix argument.
> I want to get the matrix whose entry is the functional value for each entry
> of a matrix argument.
> When the function contains no "if then" close, I get the desired result as
> the following function "f".
> However when the function contains "if then "close, the function returns the
> inverse matrix as the following function "g".
> It is because "x>1" is false as a matrix and “else part” is executed as
> inverse matrix calculation.
> I want to get the code that "if then" is applied for each entry of matrix.
> Please teach how to get such a code.
> 
> **code****
> function a=f(x)
>    a=x+1
> endfunction
> X=[1,2;3,4]
> f(X)
> 
> function b=g(x)    if x>1 then
>        b=x+1
>    else
>        b=1/x
>    end
> endfunction
> X=[1,2;0.1,-0.1]
> g(X)//returns inverse(X)
> 
> 
> 
> 
> --
> View this message in context: http://mailinglists.scilab.org/qustion-on-functional-argument-tp4032100.html
> Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users




More information about the users mailing list