Hot answers tagged functions
10
A little bit more. Still not fully diagnosed, but the problem isn't due to DSolve
... :
s1 = DSolve[{x'[t] == f*x[t] (1 - (x[t]/b)) - l x[t]}, x[t], t];
s2 = DSolve[{x'[t] == e*x[t] (1 - (x[t]/b)) - l x[t]}, x[t], t];
And the problem shows up when matching the initial condition:
Solve[(x[t] /. s2[[1]] /. t -> 0) == 4/10, C[1]]
(*
{{C[1] -> ...
8
From documentation:
Nearest[{elem₁ -> v₁, elem₂ -> v₂, …}, x] gives the vᵢ corresponding to the elemᵢ to which x is nearest.
Nearest[data] generates a NearestFunction[…] that can be applied repeatedly to different x."
We can use these two points as below.
pts = RandomReal[{-1, 1}, {1000, 3}];
nf = Nearest[Thread[pts -> ...
6
The problem can be reduced to the DSolve expressions:
DSolve[{x'[t] == a*x[t]*(1 - (x[t]/b)) - l*x[t], x[0] == 0.4}, x[t], t]
DSolve[{x'[t] == h*x[t]*(1 - (x[t]/b)) - l*x[t], x[0] == 0.4}, x[t], t]
One can see that alphabetical order appears important:
With[{a = Symbol@#},
Shallow @ DSolve[{x'[t] == a*x[t]*(1 - (x[t]/b)) - l*x[t], x[0] == 0.4}, x[t], ...
4
After you call Get, you run a packet loop, waiting for the ReturnPacket. But you never read or discard the contents of that ReturnPacket. That means that the whatever expression that Get returns (it will be the result of last evaluation in the myscript.m file, perhaps the symbol Null) is still waiting on the link. Then you call your function and wait for the ...
4
First, I'd like to point out that your "JoinH" function is already implemented by Join:
a = {{1, 2}, {3, 4}};
Join[a, a + 5, 2]
{{1, 2, 6, 7}, {3, 4, 8, 9}}
Second, you don't need Flat or whatever if you write the function to natively handle multiple arguments:
jh[m__] := Transpose[Join @@ Transpose /@ {m}]
jh[a, jh[a + 5, a + 11]]
jh[a, a + 5, a + ...
3
Something like this?
functionList1 = Table[Evaluate[#*i*i] &, {i, 0, 4}]
functionList2 = Function[x, x^2 # &] /@ Range[0, 4]
functionList1[[3]]@10
functionList2[[3]]@10
(*
{0 &, #1 &, 4 #1 &, 9 #1 &, 16 #1 &}
{0^2 #1 &, 1^2 #1 &, 2^2 #1 &, 3^2 #1 &, 4^2 #1 &}
40
40
*)
3
Perhaps this is what you want?
functionList = Table[With[{i = i}, #*i*i &], {i, 0, 4}]
functionList[[3]][10]
{#1 0 0 &, #1 1 1 &, #1 2 2 &, #1 3 3 &, #1 4 4 &}
40
The With is used to get the values inside Function, which has the HoldAll attribute, as described in: Using pure functions in Table
3
You will need to make pnorm into a black-box function so that it never tries to evaluate symbolically. Also it is probably worthwhile to use NMinimize/NMaximize in both. Finally the minimax process seems to behave better if you take pth powers in the inner optimization.
pnorm[aa_, p_] /; MatrixQ[aa, Element[N[#], Reals] &] := Module[
{m, n, x, y, f, ...
3
Forgive me my ignorance to not try your sample code and instead give you an idea for a completely different approach. Since you are just launching a MathKernel in your MathLink program, why don't you use the -run option, to load your package during the launch?
You can test this directly in the front end
kernel = LinkLaunch[
First[$CommandLine] <>
...
3
Print returns Null, and you're returning a list of values, some of which are also Null. So:
ReverseList[ele_List] :=
Module[{list = List[], i, k = 1},
For[
i = Length[ele], i > 0, {i--, k++},
{AppendTo[list, ele[[i]]]}];
Print[list];
list]
would be slightly better, perhaps?
(Obviously you wouldn't really reverse a list ...
2
I think I understand what your trouble might be. Here is your code:
a := b means that the left-hand-side is a pattern and the right-hand-side should be evaluated when that pattern is found (roughly speaking). The right-hand-side in this case is:
Your function in essence returns the entire module. You can see this by changing Module to something else, ...
2
Here's an even simpler way to create a "list" of functions, just define the function to have two arguments. To follow your example:
f[i_, t_] := t i^2
So now if you want the 5th function, it's
f[5,t]
which gives 25 t. Or you can evaluate it at any point:
f[5,7]
to get 175. If you wanted f to behave more like a proper list so as to accept only ...
1
Not sure exactly what you're looking for, but perhaps one of these steps will help.
(1) Create a list of functions you wish to apply:
fcnlist = {Sin, Cos, Tan}
(2) Now define myfunc using a pure function which applies the selected function from fcnlist to an argument x of your choice:
myfunc[f_, x_] := fcnlist[[#1]] /@ {#2} &[f, x]
(3) To generate ...
Only top voted, non community-wiki answers of a minimum length are eligible


