Does swift have natural log function in it? - swift

I am writing some functions that will solve problems for me and it requires the use of ln (natural log) but I can't seem to find it in swift and I've searched all over the internet but I still can't find the answer. Any help would be appreciated.
let rate : Double = log(finalAmount / initalAmount) / time
return rate
log should be ln.

import Foundation and you'll find log() is implemented for all the real number types. As is log10() and other specialist log functions.

Related

How math function powr() from the frameworks RenderScript works?

powr(2.0, 2.0) = 4.0
powr(-2.0, 2.0) = ?
Please tell me.
The documentation is not quite clear.
Thanks
The docs say that the first parameter (base) needs to be between 0.f and 256.f. You can't use it with a negative input.
P.S. RenderScript has been deprecated - https://developer.android.com/guide/topics/renderscript/migrate. You may want to consider this before writing further code using it.

Expression Language support in Golang

I am trying to implement a functionality that lets users try out configurations in run rime.
Basically, there are some preexisting configurations in DB, but users can make some tweaks on top of those and see results.
This component is written in Golang. One approach i am thinking is about using expression language support. I found some open source packages like https://github.com/araddon/qlbridge
But there are almost negligible number of sample programs / tutorials that demo how to use expression language along with PostgresQL.
Has any one used and attempted such thing? Any suggestions are welcome. Thank you for your time!
Try https://github.com/antonmedv/expr – is an engine that can evaluate expressions.
It can handle expressions like this:
user.Group in ["good_customers", "collaborator"]
len(article.Comments) > 100 and article.Category not in ["misc"]
product.Stock < 15
all(Tickets, {.Price >0})
And also has static type checker and user-friendly error messages
error: unclosed "("
| (boo + bar]
| ----------^

'Symbolic Math Toolbox' functions exist in MATLAB but not in the documentation

This problem may seem a bit weird; please bear with me.
When I try to access any function in the 'Symbolic Math Toolbox' in MATLAB, such as help ztrans or help laplace, I get the following kind of message
ztrans not found.
Use the Help browser Search tab to search the documentation, or
type "help help" for help command options, such as help for methods.
However, the toolbox seems to be installed when I try the ver or pathtool command.
Moreover, when I try some simple code such as:
>> syms k x
>> f = sin(k);
>> ztrans(f, k, x)
the code works fine and on trying the help command again, they seem to work fine as well. However, the problem again arises when I close and reopen MATLAB.
I found a few instances of other users facing similar problems on the Mathworks portal, but none of them seemed to provide any concrete solutions. Some of them seem to blame it on MATLAB hashing the tollbox incorrectly, so I tried the rehash toolbox command as well, but had no luck.
I'm not sure if this problem is just for this particular toolbox or not, but the other toolboxes I use at least seem to work fine.
EDIT-I
I also realised that the documentation is always available when I take Help --> Product Help from the menu-bar, though it is not available in the function browser even after I try the sample code.
EDIT-II
>> license('checkout','Symbolic_Toolbox')
gives me
ans =
1
I'm not working on a student license either.
It could be a license issue. Try to get further information with:
license('inuse')
If you have a Student version, some functions cannot be executed.
istudent
In case that you are in an office/university, and you have floating licenses. Be sure to check-out all the licenses before running your code.
license('checkout','toolbox_name')

Have Matlab type a string as if from keyboard

I was wondering if anyone knew if it is possible to have MATLAB type a string for you, as if the user had typed it on the keyboard. I believe it can be done using a shell script or an applescript, but I was wondering if Matlab had a native implementation.
I have tried searching around for it, but have not had any luck. It is not super necessary, but I am just super lazy and want to write a script that will automatically enter information into an application after MATLAB has calculated stuff.
If you know of another simple way of doing this, let me know as well. Thanks a lot!
EDIT:
Adding some code that I used in response to an answer below, using the Java Robot Class
function robotType(text)
import java.awt.Robot;
import java.awt.event.*;
SimKey=Robot;
for i = 1:length(text)
if strcmp(text(i),upper(text(i))) == 0 || all(ismember(text(i),'0123456789')) == 1
eval(['SimKey.keyPress(KeyEvent.VK_',upper(text(i)),')'])
eval(['SimKey.keyRelease(KeyEvent.VK_',upper(text(i)),')'])
else
SimKey.keyPress(KeyEvent.VK_SHIFT);
eval(['SimKey.keyPress(KeyEvent.VK_',upper(text(i)),')'])
eval(['SimKey.keyRelease(KeyEvent.VK_',upper(text(i)),')'])
SimKey.keyRelease(KeyEvent.VK_SHIFT);
end
end
end
Warning, code may not be the best, but hey it was written in like 5 minutes.
I ended up writing an applescript to do everything that I needed Matlab to do. Unfortunately this will not help the Windows people, but myself and the other people using the script are mac users, so it works for us.
I have however, edited my question above to include code that I used initially in Matlab to auto type things. Simply run command as robotType('SomeString') and it will type that string.
I do not believe it will hand spaces or random characters that well, or at all, but it is good enough for abc123. Sorry for no final solution on this.

smlnj listdir problems

I am a newbie learning sml and the question I am given involves IO functions that I do not understand.
Here are the 2 questions that I really need help with to get me started, please provide me with code and some explanation, I will be able to use trial and error with the code given for the other questions.
Q2) readlist(filename) which reads a list of filenames (each of which were produced by listdir in (Q1) and combines them into one large list.
(reads from the text file in Q1 and then assigns the contents into 1 big list containing all the information)
Thing is, I only learned from the lecturer in school on the introduction section, there isn't even a system input or output example shown, not even the "use file" function is taught. if anyone that knows sml sees this, please help. Thanks to anyone who took the effort to help me.
Thanks for the reply, current I am using SMLNJ to try and do this. Basically, Q1 requires me to list the directory's files of the "directoryname" provided into a text file in "filename". The Q2 requires me to read from the "filename" text file and then place the contents into one large list.
BTW, if you people only kept seeing this post, please try and ask questions also. Currently i am stuck trying to read from the txt file and appending it to a list, I am able to do it for a single line but am now trying to do it for the whole file:
fun readlist(infile : string) =
let val ins = TextIO.openIn infile
fun listing() =
TextIO.inputLine ins;
in listing()
end;
TextIO.closeIn;
It is very hard for me to make out what questions you are trying to ask.
The functions you ask about are not part of the Standard Basis Library for ML. If you are supposed to write them, you are going to have a hard time without some kind of Posix module. You can tell your instructor I didn't care for this assignment.
Moscow ML contains a listDir function which is admirably simple:
- load "Mosml";
> val it = () : unit
- Mosml.listDir ".";
> val it = ["natural-semantics.djvu", "natural-semantics.pdf"] : string list
-
To get more help, please be a little clearer what you are asking.
EDIT: Since it's a homework question I shouldn't just give you the answer, but some useful functions includeopenDir, readDir, and closeDir from the OS.Filesys structure. These will tell you what's in the directory. Then to read and write files you'll want TextIO.
You'll find the Standard Basis Library documentation indispensible.
You sure i didn't teach u?
u owe me one chicken pie.