Help with casio fx-9860G - basic

I need help writing custom functions for my casio fx-9860g
I have done this before in my Texas Calc but Im not sure there is a way to it with casio calculators... say, for instance, I want to write a simple function like so:
public int triple(int x)
{
return 3x;
}
I understand this is quite a simple function but I want a way to store some formulas so I can quickly calculate stuff without having to rewrite the formulas all over again.. thanks in advance.

Casio basic doesn't have 'functions' like you want. For simple functions you use copy/paste, rather than abstract using functions. (This redundancy is better than you'd think)
For larger sub-routines you can write those as a program file and call them. See the prog and return commands in the manual.
File: "MySub"
----------------------
Y <- X * 3
return
File "MyProgram"
----------------------
X <- 5
Prog "MySub"

Related

Creating graphs using code from Pari-GP, but using Sage's graphing tools

everyone!
I know this is probably a dumb question, but I'm having a lot of trouble with Sage, and it's frustrating the hell out of me. To give a bit of an explanation, I code entirely in pari-gp. I don't have a single problem with my code in pari-gp, I'm just having trouble with interfacing my code with Sage. Which, this is something Sage bolsters, that you can run pari-gp code within sage. I essentially want to run all my processes in pari-gp, but I want to exploit all of Sage's graphing protocols.
What I want to do couldn't be easier. I have a well working function test(x,y), which produces a real number. I don't have any problems running this in pari, everything is kosher. All I want to do is make a graph of test(x,y) = z. Now I know how to run this command in sage, but I don't know how to interface such that test is actually a program running from Pari code.
I'd love to program all my stuff in Sage, but that's just impossible. I need the language Pari, so before you say that I could just translate everything in Sage, it's impossible. I just can't wrap my head around how to interface Pari with Sage. I know it's possible; hell, they advertise it on the main website. I'm just very unclear about how to do the following:
1.) Read a file from my pari-gp root directory: gp.read("myfile.gp").
2.) Inherit the functions, such that gp("test(x,y)"), now runs as though it runs in the GP terminal.
3.) Graph said function test(x,y) using Sage's graphing protocols.
Any help is greatly appreciated. I know I'm just forgetting to do something dumb, or I'm missing a step in how I'm doing it.
Any help is greatly appreciated!
Let us start with:
sage: gp("test(x, y) = sin(x*y)")
(x,y)->sin(x*y)
sage: gp("test(1, 1)")
0.84147098480789650665250232163029899962
sage: type(_)
<class 'sage.interfaces.gp.GpElement'>
So the printed version of gp("test(1, 1)") looks like a number, but it is not a float instance. Note that py3 has some f-strings, so we can easily plug in values of variables x, y inside the gp("test(...)") . I will use f-strings to define the sage function...
And we are not far away from the final plot:
sage: f = lambda x, y: float( gp(f"test({x}, {y})") )
sage: plot3d(f, [0, pi], [0, pi])
Launched html viewer for Graphics3d Object

How to represent an anonymous function as a string

I want to represent a function like x->x^2 as a string - simply doing string(x->x^2) doesn't work, is there any way around this?
You could create a function from string using fun=eval(parse("x->x^2")) but as far as I know it's an irreversible process.
Just because something works, doesn't mean it is a solution... Suppose f is the anonymous function. With f = x->x^2. Then the following:
join(map(strip,match(r"line \d*:\n(.*)\n",string(f.code)).captures),"\n")
Gives:
return x ^ 2
More can be extracted using regular expressions from f.code. Also note this doesn't work for non-anonymous functions. And it isn't something one should rely on to work. Perhaps some other way to implement the functionality would be best.

Using bessel functions in MATLAB

I'm trying to put all of my functions from Excel workbook into MATLAB. I'm having an issue using bessel functions in MATLAB. I'm simply not getting the same results from MATLAB as I do in excel.
For example, in excel if I execute
=0.32*BESSELI(0.32,0)/2/BESSELI(0.32,1)
I get 1.012.
When I use the same approach in MATLAB
0.32*besseli(0.32,0)/2/besseli(0.32,1)
I simply get zero.
Can someone please help me integrate bessel functions into my MATLAB script so that they provide the same answer as they do when used in excel?
MATLAB and Excel have the arguments of the besseli function in a different order.
The following expression (note the order of arguments changed):
0.32*besseli(0, 0.32)/2/besseli(1, 0.32)
will yield:
> ans = 1.0127
in MATLAB.
The documentation shows the formulae and show that if you use Z=0, which you have in your first besseli, you should get 0, which you do. The second call to besseli should not get you zero, and indeed it does not:
besseli(0.32,1)
ans =
1.0744
I copied the following from the aforementioned documentation:
This shows that unless your nu (that Greek thing that looks like a v) is zero, your modified Bessel function of the first kind at Z=0 will be, in fact zero.
On a side note: why are you doubly dividing and not simply writing
0.32*besseli(0.32,0)*besseli(0.32,1)/2

Turning a list into a set of coordinates [Haskell]

I am a starting out programmer and have my first few programming classes. We started off with functional programming, in this case using Haskell. I've managed to complete a few assignments already, but seem to have gotten stuck in one point and was hoping to get some help with it.
In order to not bore you with the entire code, my program right now is extracting a list of commands from a text file. I need to turn this list into a set of coordinates. What I mean is something along the lines of:
function :: [String] -> (Int, Int, Char)
where the function will receive, for example, the list ["0 0 N"] and output the coordinates and direction (0, 0, N).
I tried doing:
function [x y o] = (show x, show y, read o)
which would work if it were just Integers. I can't seem to get the Char part to work. I appologize if it's such a noobie question, but bear with me, please, I'm really new to all of this.
Thank you and best regards!
For your specific test case this should work:
function [(x:' ':y:' ':o:_)] = (read [x], read [y], o)
If your string contains spaces you need to match on them as well if you want to do it like that.
But that's probably not what you actually want. It would break for inputs like ["12 23 S"] or ["3 5 W", "2 8 E"].
If your input is actually a list of Strings like your signature says you should probably write two functions: One that deals with a single String and one that applies your other function to all Strings in the list. Look at the functions map and words and think about how you can use them to solve your problem.

Unicode name from Char

I'm looking for a function that takes a Char as input and gives the unicode name of that code point (::Char->String), but I couldn't find any results on Hoogle. I assume that there is no builtin (If there is, please let me know) and so I wonder what's the best way to write this function and its inverse (::String->Maybe Char).
I know you'd have to read UnicodeData.txt or a similar document, but I don't know what the best/fastest function would be.
The unicode-names package contains the function
getCharacterName :: Char -> String
First of all, thanks to #TwanVanLaarhoven who provided an excellent answer. I did however need a function that did the reverse of getCharacterName.
What I originally wanted was a function that would read the file and not have it hard-coded, but I eventually realized that that would require unsafe IO operations.
What I decided to do was to copy UnicodeData.txt into notepad++ and use the following regex replacements:
write module UnicodeNames (characterToName,nameToCharacter) where
paste UnicodeData.txt
replace this: ^([\dA-F]+);([^<;>]+).*$|^([\dA-F]+);(?:[^;]*;){9}([^<;>]+).*$
with this: characterToName '\\x$1$3' = "$2$4"
append characterToName _ = ""
paste again
replace this (again): ^([\dA-F]+);([^<;>]+).*$|^([\dA-F]+);(?:[^;]*;){9}([^<;>]+).*$
with this: nameToCharacter "$2$4" = Just '\\x$1$3'
append nameToCharacter _ = Nothing
replace ^.*<.*$ with nothing to remove extra lines.
The file will be incredibly long and take forever to compile :-) In addition to having an inverse function, this method has the advantage of providing more names than the unicode-names package by using unicode 1.0 names as well. The two functions in this file rely on pattern matching to act as a dictionary from char to string and vice-versa. I would put my solution on PasteBin or somewhere else if it didn't use a ton of memory.

Resources