Tag Info

Hot answers tagged

10

There is an example of what I think you are trying to do at the end of WeatherData help page, but its a little hard to read. However - here's what I think you want. (* Function to Get a list consisting of {CityName, Temp, Co-ords} given a Countries weather station, note we get the 1st nearest weather station to the city *) weatherdata[cityname_] := ...


6

WeatherData can be told to give you all the weather stations it knows about, but there's more than one type of weather station (and duplicates!): allWeatherStations = WeatherData[]; fullformStations = FullForm /@ allWeatherStations; Tally[StringLength /@ fullformStations[[All, 1, 2]]] (*{{4, 6919}, {5, 10306}, {8, 4697}}*) Looking at the documentation, I ...


5

To illustrate whats going on, your function is 0 at x=0, rises to a max and becomes essentially zero very quickly. With[{a = .9}, Plot[x Exp[-(a^2+.001^2) x^2], {x, 0, 3}]] Now look at the values NIntegrate computes: res = Reap[With[{a = .9}, NIntegrate[y = x Exp[-(a^2 + 0.001^2) x^2], {x, 0, 8000}, EvaluationMonitor :> Sow[{x, ...


4

What the OP is trying to code is already in Mathematica in the form of ParametricNDSolveValue. myodessystem = ParametricNDSolveValue[{y'[x] == k1 y[x] Cos[k2 x + y[x]], y[0] == 1}, y, {x, 0, time}, {k1, k2, time}] (* ParametricFunction[<>] *) mysolve = myodessystem[1, 1, 30]; mysolve[1] (* 0.991387 *)


3

Treat the maximum machine number as a singularity: ListPlot[Table[{a, NIntegrate[x Exp[-(a^2 + 0.001^2) x^2], {x, 0, 0.5 Log[$MaxMachineNumber/(a^2 + 0.001^2)], 8000}]}, {a, 0.001, 1, 1/100}], Joined -> True Update [Forgive me, I actually have a job, and, while I could solve the problem quickly over breakfast, I could not compose a complete ...


3

Dilation produces the same output as MaxFilter and has comparable speed. test = {5, 6, 9, 3, 2, 6, 7, 8, 1, 1, 4, 7}; Dilation[test, 1] (* {6, 9, 9, 9, 6, 7, 8, 8, 8, 4, 7, 7} *) It also has a Padding option which may be convenient: Dilation[test, 1, Padding -> 10] (* {10, 9, 9, 9, 6, 7, 8, 8, 8, 4, 7, 10} *) Dilation[test, 1, Padding -> ...


3

Note change at end of your function... you might also want to add checks to ensure that there was a solution so as not to return a nonsense function. myodessystem[k1_, k2_, time_] := Module[{odes, y, x, sol, myfun}, odes = {y'[x] == k1 y[x] Cos[k2 x + y[x]], y[0] == 1}; sol = NDSolve[odes, y, {x, 0, time}]; myfun = First[y /. sol]]; mysolve = ...


2

With N replaced by n and exact numbers, the function in the Question can be written as f[n_] = Sum[Binomial[n/2 - 1, a]*Binomial[n/2 - 1, a - 1]*(7/20)*(3/10)^(n - a - 1), {a, 2, n, 2}] Although Mathematica can perform the Sum, the result in terms of HypergeometricPFQ is not particularly enlightening. Instead, plot f[n]. ListLogPlot[Table[f[n], {n, ...


2

This is a quick and dirty version for what I think you are trying to do. Note that its not good Stack Exchange practise to keep asking variations of the question. One caveat with the Export help is that most useful stuff is held under each file format - so try looking at the help for XLSX. a = {"WMO44203", "WMO44207", "WMO44212"}; dset = WeatherData[#, ...


1

As @Kuba mentioned in his comment, you have one syntax error that prevents evaluation of your code: you missed a parameter (Kp) in the list of parameters passed to NonlinearModelFit. Using the value of data defined in your question, here is the updated version with all the necessary parameters: NonlinearModelFit[ data, (kt (x y - z/Kp))/(1 + Sqrt[x ka2] + ...


1

Use Piecewise for discontinuous right-hand sides and coefficients. If, with a capital I, more a programming construct than an algebraic/functional one. NDSolve does discontinuity processing, which improves error estimation and step size when done accurately; using Piecewise helps with that. s = NDSolve[{ Derivative[1][Ca][t] == Piecewise[{{-10*Ca[t] + ...


1

First, a fixed version of your code: ClearAll[eOF0, eOF1, eOF2, eOF3] eOF0[int_, dt_, nas_, nts_] := Module[{d = ConstantArray[2, {nas + 1, nts}]}, For[j = nts, j > 1, j--, d = ReplacePart[d, {1, j - 1} -> (1 - int*dt)*d[[1, j]]]]; Grid[d]] eOF0[0.01, 0.1, 4, 4] and a few alternatives eOF1[int_, dt_, nas_, nts_] := Module[{d = ...



Only top voted, non community-wiki answers of a minimum length are eligible