I have defined the function:
g[x_] = TransformedDistribution[ u + v , {u \[Distributed] ParetoDistribution[1, 1], v \[Distributed] ParetoDistribution[1, 1]}];
PDF[dist,x]
However, when I want to integrate g[x] from k to infinity :
Integrate[g[x] , {x,k , \[Infinity] } ]
Mathematica does not output anything.
Any recommendations on how to solve this or how I could get the function that was outputted when I first defined g[x] and then doing the integration ?
Thank you
I think you just have your function syntax wrong, try this:
g[x_] = PDF[
TransformedDistribution[
u + v, {u \[Distributed] ParetoDistribution[1, 1],
v \[Distributed] ParetoDistribution[1, 1]}], x]
when you integrate you need to add the condition that k is real:
Integrate[g[x], {x, k, Infinity}, Assumptions -> Element[k, Reals]]
1 k<=2
(2 (k + Log[-1 + k]))/k^2 k>2
Related
In gnuplot, is there a way to pass a user defined function as an argument to another user defined function? For example, I can write a function loop which will sum shifts of a given function:
f(x) = (x <= 0) ? 0 : 1/(1+x)**2
loop(x, i, s) = (i == 0) ? f(x) : loop(x-s, i-1, s) + f(x)
Then I can do things like:
plot loop(x, 10, 1)
But, how do I define a function loop2 that does this for any function, as in something like:
loop2(g, x, i, s) = (i == 0) ? g(x) : loop2(g, x-s, i-1, s) + g(x)
so that I can then do things like:
f3(x) = (x <= 0) ? 0 : 1/(1+x)**3
plot loop2(f, x, 10, 1)
replot loop2(f3, x, 10, 1)
I think this is not possible in gnuplot 5.4.
The development version (gnuplot 5.5) has recently gained the ability to label a block of text commands as a named executable function, known as a "function block". This gives you access to commands in a function block that are not possible in a one-line user defined function. Here is your example run in a recent build of the development version. At the top level the name of the function ("f" or "f3") is passed as a parameter that can be used to construct a call of the function itself.
function $loop2(name, x, i, s) << EOF
local temp = 0
eval sprintf("temp = %s(x)", name)
return (i == 0) ? temp : temp + $loop2(name, x-s, i-1, s)
EOF
f(x) = (x <= 0) ? 0 : 1/(1+x)**2
f3(x) = (x <= 0) ? 0 : 1/(1+x)**3
set key left Left reverse
set tics nomirror
set border 3
set xrange [0:10]
set yrange [0:1.5]
plot $loop2("f", x, 10, 1), $loop2("f3", x, 10, 1)
And here is a link to an example in the demo collection that illustrates calling one function block from another, wrapping both in a top-level user defined function.
function_block demo
I want to solve the following equation with Octave:
syms y(t) k T T1 % k, T and T1 are constants.
eq1 = diff(y,t)-k*y+k*T == 0
cond=y(0)==T1
dsolve(eq1,cond)
but Octave runs it like this:
{
(sym)
k⋅t
y(t) = T + (-T + y(t))⋅ℯ
}
Octave cannot solve this!!. Does anyone know the answer to this problem?
I would like to define a list using a for loop and I need to do it using a function of the n-iterate.
I have:
Initialization
In[176]: Subscript[y, 0] = {1, 2, 3}
Out[180]: {1,2,3}
The function:
In[181]: F[n_] := For[l = 1, l++, l <= 3, Subscript[y, n + 1][[l]] :=Subscript[y, n][[l]]+ n]
I call the function
F[0]
and I get:
In[183]: Subscript[y, 1]
Out[183]: Subscript[0, 1]
I should have {1,2,3}.
Anyone know why it isn't working as it should?
I have troubles recreating your error, problem.
I understand you want to add n to your vector, where n is the number of the subscript.
Here's another way to have a go at your question, avoiding the loop and the subscripts:
Clear#y;
y[0] = {1, 2, 3};
y[n_Integer] : =y[n - 1] + n
(as Plus is Listable, you can just add n to the vector, avoiding the For)
and then call it using, e.g.
y[0]
{1,2,3}
or
y[5]
{16,17,18}
Alternatively, using memoization, you could define y as follows:
y[n_Integer] := y[n] = y[n - 1] + n
This will then store already calculated values (check ?y after executing e.g. y[5]). Don't forget to Clear y, if y changes.
Obviously, for a function as this one, you might want to consider:
y[n_Integer] := y[0] + Total[Range[n]]
I have followed the tutorial on http://www.mit.edu/people/abbe/matlab/ode.html and prepared a function as follows:
function dxy = diffxy(xy)
%
%split xy into variables in our equations
%
x = xy(1);
xdot = xy(2);
y = xy(3);
%
% define the derivatives of these variables from equations
%
xdot = xdot;
ydot = 3*x + 2*y + 5;
xdoubledot = 3 - ydot + 2*xdot;
%
%return the derivatives in dxy in the right order
%
dxy = [xdot; xdoubledot; ydot]
end
When I call it using
[T, XY] = ode45('diffxy',0,10,[0 1 0])
I get an error
??? Error using ==> diffxy
Too many input arguments.
I also tried
XY= ode45(#diffxy,[0 10],[0;1;0])
Anybody have any idea?
haven't read the whole tutorial but aren't you supposed to define your function as
function dxy = diffxy(t, xy)
where t is time vector
I have encountered the following system of differential equations in lagrangian mechanics. Can you suggest a numerical method, with relevant links and references on how can I solve it. Also, is there a shorter implementation on Matlab or Mathematica?
mx (y dot)^2 + mgcosy - Mg - (M=m)(x double dot) =0
gsiny + 2(x dot)(y dot + x (y double dot)=0
where (x dot) or (y dot)= dx/dt or dy/dt, and the double dot indicated a double derivative wrt time.
You can create a vector Y = (x y u v)' so that
dx/dt = u
dy/dt = v
du/dt = d²x/dt²
dv/dt = d²y/dt²
It is possible to isolate the second derivatives from the equations, so you get
d²x/dt² = (m*g*cos(y) + m*x*v² - M*g)/(M-m)
d²y/dt² = -(g*sin(y) - 2*u*v)/x
Now, you can try to solve it using standard ODE solvers, such as Runge-Kutta methods. Matlab has a set of solvers, such as ode23. I didn't test he following, but it would be something like it:
function f = F(Y)
x = Y(1); y = Y(2); u = Y(3); v = Y(4);
f = [0,0,0,0];
f(1) = u;
f(2) = v;
f(3) = (m*g*cos(y) + m*x*v*v - M*g)/(M-m);
f(4) = -(g*sin(y) - 2*u*v)/x;
[T,Y] = ode23(F, time_period, Y0);