Ti Nspire: Convert solve(...) output to a callable Function - ti-basic

in order to calculate the inverse function of f(x) I defined following function:
inv(fx):=exp▶list(solve(fx=y,x),x)
which output is:
inv(x^(2)) {piecewise(−√(y),y≥0),piecewise(√(y),y≥0)}
So that part works already, but how can I use this result as a callable function i(y)?
Thanks for your help

Outside of your program, you can turn the result into function i(y) with:
i(y):=piecewise(-√(y),y≥0,√(y),y≥0)
I do not have a CAS, so your results may differ, but, because the function can only return one value, it would only return (and display in the graph) the first value, in this case, -√(y). If you want to display on the graph or get the values of both, you would be better off creating two separate functions (-√(y), and √(y)). Hope this helps you "use the result as a callable function."

Related

Unable to understand proper use of randomSeed() in custom functions

The random value is coming out to be different even when randomSeed() is initialised inside the setup() method.
For example:
function setup() {
createCanvas(400, 400);
randomSeed(400);
console.log(random(100));
}
function draw() {
console.log(random(100));
check();
noLoop();
}
function check(){
console.log(random(100));
}
Here, the three functions are giving different random values. Similarly, if I have a couple of functions like funcA, funcB, funcC etc, how to get a same random value throughout the program?
Similarly, if I am using noise() function, is there a way to get the same noise value every time the program is run when I am adding noiseSeed() in the setup() function?
What do you mean by "The random value is coming out to be different"?
If you mean, that each call to random(100) results in a different value, that is the expected behavior!
Each call to random(100) results in a random value, but if you restart the program, you will get the same values again.
For me, your program results in
39.10889436956495
56.007297383621335
70.2842695871368
Every single time I run it.
If you remove randomSeed(400);, every time you start the program, the values will be different.
If you want random(100) to always return the same value, don't use the function, just replace it with the value you want.
But if by "The random value is coming out to be different" you mean, that running the program multiple times will result in different output for you, then something is broken in your setup.

Mlrose TSPOpt Genetic Algorithm own cost function

I want to program my own cost function for my own TSP problem. I do not want to use the mlrose one, because I want to optimize real coords with time.
First of all, I created a coords_List which looks like this: [(49.321,8.213),[50.321,9.124]...)
Then I created my own fitness function which accepts the guess array and returns a float.
fitnessF = mlrose.CustomFitness(coords_list)
Now I set up mlRose:
problem_fit = mlrose.TSPOpt(length = len(coords_list),fitness_fn =fitnessF, maximize=False)
best_state, best_fitness = mlrose.genetic_alg(problem_fit, random_state = 2)
This returns:
Exception: fitness_fn must have problem type 'tsp'.
Now I set up the code like this:
fitnessF = mlrose.TravellingSales(check_fitness)
Now it will return:
object of type 'function' has no len()
Thanks in advance
Ps: I would also be ready to share my notebook over Email
I could figure out where the problem was. It is right that I have to define my custom fitness function, but for TSP I have to add the problem type:
fitnessF = mlrose.CustomFitness(coords_list,"tsp")
Now it will work.

Inside a function, how do I construct a new function based on original function parameters, in order to pass as an argument to another function

I'm having trouble with function declarations and scope in julia. I have a main function, let's call it mainfunc which accepts some arguments. Within this function, I would ultimately like to call a different function, say callfunc, which takes a function as an argument. This function I will call passfunc.
One further complication I have is that there is a final function which I define outside of the logic which depends on the arguments but still depends on the arguments in a different way. I can call this initfunc. This must be composed with some other function, depending on the arguments, to create passfunc.
Based on the arguments given to mainfunc, I will have different definitions of passfunc. Given the answer I got to a related question here, I initially tried to define my function logic in the following way, using anonymous functions which are apparently more efficient:
function mainfunc(args)
init_func = x -> funcA(x, args)
if args[1] == "foo"
anon_func = x -> func1(x, args)
elseif args[1] == "bar"
anon_func = x -> func2(x, args)
end
function passfunc(x)
return init_func(x) + anon_func(x)
end
# ... define other args...
callfunc(passfunc, other_args)
end
Defining my function in this way leads to errors in julia - apparently passfunc is an undefined variable when I run this code. Does the scope not allow the anonymous functions to be defined in the if statements? How else could I write code that achieves this?
I feel like a better understanding of functional programming principles would make the solution here obvious. Thank you in advance for any tips you can offer on improving this.
Also, I am running this with julia v0.7

Returning multiple values in UDF

I have written an AggregateFactory Vertica UDF which returns a single value
getReturnTypes(si,columnTypes args,columnTypes returnTypes){
returnTypes.addVarbinary(512);
//I want to add second returnType
returnTypes.addFloat("");
}
getProtoType(si,columnTypes args,columnTypes returnTypes){
returnTypes.addVarbinary(512);
//I want to add second returnType
returnTypes.addFloat("");
}
this is not working, how can I return two values from an AggregateFactory UDF?
You cannot. User Defined Aggregate Functions (as explained in the fine manual) return ONE value per group. You might want to write a User Defined Transform Function (maybe a multi-phase Transform Function).

Returning other values from d3.call

Per the docs, "The call operator always returns the current selection, regardless of the return value of the specified function." I'd like to know if there is a variant of call or reasonable workaround for getting call-behavior that returns values other than the selection.
Motivation:
I've got a chart and a datebrush, each encapsulated in a function
function trends_datebrush() {
// Setup
function chart(_selection) {
_selection.each(function(_data) {
// Do things
...});
}
return chart;
};
(The chart follows a similar format but isn't called datebrush).
These are instantiated with:
d3.select("someDiv")
.datum("data")
.call(trends_datebrush());
// And then we call the chart
I'd like to return a subselection from brush to be used as the data variable in the chart call. As is I need to make them both aware of some higher order global state, which gets messy especially since I want other control functions to drill down on the data. If I could override call, then I could do something like
d3.select("someDiv")
.datum("data")
.call(trends_datebrush())
.call(trends_chart());
And then if I were to implement some new filter I could throw it into the chain with another call statement.
tl;DR: Looking for ways to get chain chart calls s.t. they can pass transformed data to each other. I want monadic D3 charts! Except I don't really know monads so I might be misusing the word.

Resources