Decimal value is not recognized by F# console [closed] - f#

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I'm practicing F# for the first time and I thought I'd try to make a program that would calculate the areas of different kinds of shapes. However, the portion that finds the area of a circle is giving me a lot of trouble.enter code here
elif stringInput = "2" then
let PI = 3.14156
printfn "What is the circle's radius: "
let radiusString = System.Console.ReadLine()
let radiusInt = radiusString |> float
let cirlceArea = (radiusInt * radiusInt) * PI
printfn "The area of the circle is : %d" cirlceArea
I'm sure it has something to do with the radiusString |> float part of the code, but nothing I've tried works and I've had no luck in finding any examples that can help. What can I do?

Ok I just found out the problem was that I was using %d instead of %f

Related

Max intensity projection ImageJ from selected slices [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am trying to write macro to pick up slices which I would like to include in my MIP. So far it looks like this:
LowerStack = getNumber("prompt", 10);
UpperStack = getNumber("prompt", 10);
run("Z Project...", "start=" + LowerStack) ("stop=" + UpperStack) ("projection=[Max Intensity]");
It recognizes the Lower slice which I want to pick up, but not the upper one.
Any suggestions on what do I do wrong?
The syntax of the third line is incorrect. This works:
LowerStack = getNumber("Lower", 10);
UpperStack = getNumber("Upper", 10);
run("Z Project...", "start=" + LowerStack + " stop=" + UpperStack + " projection=[Max Intensity]");
Note that I also changed the string in the two prompts because you would likely get an error by them not being unique.

Why is this haskell function giving me a parse error? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying to say if the desired location in the field is 1 return true otherwise return false. Why is this code not working?
fireShot :: Coordinate -> Field -> Bool
fireShot coord Shipfield
| nth ( fst(coord)((nth snd(coord)) ShipField) == 1 = True
| otherwise = False
The brackets in the guard are not balanced, you open five brackets, and you close four brackets. Furthermore variables start with a lowercase, so it should (probably) be shipfield, not Shipfield.
I think it might be better to use pattern matching to obtain the first and second coordinate, since this will make the code more clean. You furthermore do not need guards to return True and False. You can replace the function with:
fireShot :: Coordinate -> Field -> Bool
fireShot (x,y) shipfield = nth x (nth y shipfield) == 1

Rounding float to next integer at .5 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I thought lroundf would round my float to the next highest number at .5 steps. E.g. 1.5f would be rounded to 2.0f.
I tried, but my code tells me otherwise:
int roundUp = 1.5f;
NSLog(#"no round up: %d", roundUp);
NSLog(#"lroundf: %ld", lroundf(roundUp));
And my output is:
no round up: 1
lroundf: 1
How do I correctly round up my float?
int rounded = lroundf(theFloat); NSLog(#"%d",rounded);
int roundedUp = ceil(theFloat); NSLog(#"%d",roundedUp);
int roundedDown = floor(theFloat); NSLog(#"%d",roundedDown);

Exponential Moving Average - Ruby [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I've been using the simple_statistics gem, but im looking to calculate the EMA on the last x records. For example (when calculating WMA)
#stockticker.ema10 = s.stocktickers.last(10).map(&:current_price).map{|f| f.to_f}.wma
I was wondering if anyone can provide advise on how I got about calculating the EMA in rails?
It looks like the Moving Averages gem might be what you're looking for. Here is a copy of their exponential_moving_average method for reference as well.
class Array
def exponential_moving_average(idx=nil, tail=nil)
idx, tail = idx_and_tail_or_defaults(idx, tail)
valid_for_ma(idx, tail)
alpha = 2.0 / (tail + 1)
n = (1..tail).to_a.map{|tidx| (1 - alpha) ** (tidx - 1) * self[idx - tidx + 1]}.sum
d = (1..tail).to_a.map{|tidx| (1 - alpha) ** (tidx - 1)}.sum
n / d
end
alias_method :ema, :exponential_moving_average
end
I am the developer of Statsample-timeseries gem which is an extension of Statsample, an advance statistical suite in Ruby. It has quite many statistical methods (including EMA) which you can perform on your data.
If you need any assistance, I will be very happy to help out. :)

Recurrence Relation working [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I am doing a data structures and algorithms paper in which recurrence relations are being taught.
The question is as follows:
From what I understand from this question, n will keep on being halved over and over again. So what you are left with is 1/32n^2 + 1/16n^2 + 1/8n^2 + 1/4n^2 + 1/2n^2 + n^2. All the fractions sum to 1. So you're left with n^2 +n^2 = 2n^2.
However this is not a possible solution.
Can somebody please help me understand how to calculate these recurrence relations correctly, or point me in the right direction because I am having a lot of trouble with this topic and any help with be greatly appreciated.
Thank you for your time.
You might want to look at the Master Theorem
In the wiki, a = 1, b = 2, c = 2, where T(n) = aT(n/b) + n^c
Case 3 applies, since 2 > 0 = log_2(1)
Thus, by the master theorem, T = Big-Theta(n^c) = Big_Theta(n^2).
Choice B has a n^2 term, so that should be your answer.

Resources