Ti基本传递函数作为另一个函数的参数 [英] Ti-basic passing function as an argument to another function

查看:171
本文介绍了Ti基本传递函数作为另一个函数的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Matlab中,您可以声明一个匿名函数并将其传递给另一个函数.

In Matlab you can declare an anonymous function and pass it to another function.

[y] = someFunction(@(x) x.^2 , [a bunch of numbers]);

我想在TI-89计算器上做类似的事情.我有一个函数将数学函数"作为其参数之一,而我正在尝试这样做:

I'd like to do something similar on my TI-89 calculator. I have a function that takes a "math-function" as one of its arguments and I'm trying to do it like this:

myfunction(3/x,1,2)

我的函数看起来像这样:

and my function looks something like this:

myfunction(f,xl,xu)
Func
local a,b
f(xl)→a
f(xu)→b
Return [a,b]
EndFunc

我知道我可以在"y ="编辑器中输入函数,然后在函数内部访问它们,但是我真的很希望能够直接将数学函数作为参数输入.我该怎么办?

I know I can input my functions in the "y=" editor and then access them inside the function but I would really like to be able to input the math-function directly as an argument. How can I do this?

推荐答案

TI-BASIC中的内置expr函数可用于将字符串转换为表达式.这是通过这种方式实现功能的方法:

The builtin expr function in TI-BASIC can be used to turn a string into an expression. Here's how to implement your function this way:

myfunction(f,xl,xu)
Func
Local a,b,x

xl→x
expr(f)→a

xu→x
expr(f)→b

Return [a,b]
EndFunc

对函数的调用将为myfunction("3/x",1,2).确保将f的定义用双引号引起来,以便将其视为字符串.

The call to your function will be myfunction("3/x",1,2). Be sure to enclose the definition of f in double quotes so it is treated as a string.

这篇关于Ti基本传递函数作为另一个函数的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆