Find root in sagemath - sage

I am very new to sagemath, so sorry for maybe too easy question. I have this equation
%var beta, N_0, V
show(exp(-beta*N_0)*(1/beta*N_0) + 1 - 1/(beta*N_0) - V==0)
I need to solve this equation for beta, but when I tried
solve(exp(-beta*N_0)*(1/beta*N_0) + 1 - 1/(beta*N_0) - V==0, beta)
it returns me.
[beta == 1/25*(e^(50*beta) - 2500)*e^(-50*beta)]
Can sagemath numerically solve this equation? Does help if I set V = 0.5 and N_0 = 50?
Thx for help.

Related

Convex optimization problem does not follow DCP rules

I am trying to solve the following optimization problem using cvxpy:
x and delta_x are (1,N) row vectors. A is a (N,N) symmetric matrix and b is a scalar. I am trying to find a y, such that it minimizes the sum of squares of (y - delta_x) with the constraint (x+y).A.(x+y).T - b = 0. Below is my attempt to solve it.
x = np.reshape(np.ravel(x_data.T), (1, -1))
delta_x = np.reshape(np.ravel(delta.T), (1, -1))
y = cp.Variable(delta_x.shape)
objective = cp.Minimize(cp.sum_squares(y - delta_x))
constraints = [cp.matmul(cp.matmul(x + y, A), (x + y).T) == (b*b)]
prob = cp.Problem(objective, constraints)
result = prob.solve()
I keep getting the error 'cvxpy.error.DCPError: Problem does not follow DCP rules'.
I followed the rules stated in the answer here, but I don't understand how to construct the proper cvxpy minimization Problem. Any help would be greatly appreciated.
Thanks!

Is there symbolic ODE solver in R ? (ODE = ordinary differential equation)

Question: Is there symbolic ODE solver in R ? (ODE = ordinary differential equation)
I am afraid there is NO... but let me confirm from experts ...
For example, solve:
> (5x-6)^2 y' = 5(5x-6) y - 2
Here: y - unknown function, y' - its derivative
(It is easy to solve by hands: y = 1/(5(5x-6)) + C* (5x-6) , but I want to get that answer from R).
What I know:
1) There are NUMERICAL (not symbolic) solvers:
I know there are numerical ODE solvers like library(deSolve),
see answer here:
Can R language find a generic solution of the first order differential equation?
2) There are symbolic packages : (but they do not seem to contain ODE solvers)
There are symbolic packages in R like
see Ryacas and rSymPy and also some basic symbolic calculation in base R, see:
https://stats.stackexchange.com/questions/4775/symbolic-computation-in-r/4778
3) Brief overview of various differential equations solvers for R:
https://cran.r-project.org/web/views/DifferentialEquations.html
However I was unable to find sumbolic ODE solvers (((
I've had a play around with Ryacas, and you can in fact get symbolic solutions to some simple ODEs without too much work. Unfortunately, YACAS fails to find a solution for your example ODE. However, depending on the ODEs you are exploring, this might still be of use. If not, I'm happy to remove this post.
As an initial simple example, let's consider the following ODE: y'' + y = 0:
Load the library
library(Ryacas);
Since Ryacas is just an interface to YACAS, we can use YACAS' OdeSolve to solve the ODE
yacas("OdeSolve( y\'\' + y == 0 )")
#expression(C70 * exp(x * complex_cartesian(0, -1)) + C74 * exp(x *
# complex_cartesian(0, 1)))
This gives the correct solution const * exp(- ix) + const * exp(+ ix).
Unfortunately when using your particular example, OdeSolve fails to find a solution:
yacas("OdeSolve( y\'\' == (5 * (5 * x - 6) * y - 2) / (5 * x - 6)^2 )")
#expression(y(2) - (5 * ((5 * x - 6) * y(0)) - 2)/(5 * x - 6)^2)
The same happens when we use the YACAS online demo.

Mathematica DSolve diff. equation over a particular domain

I am looking for a way to solve the following differential equation:
DSolve[(1 - b*Abs[z])*f[z]/a == f''[z], f[z], z]
Therefore I tried to DSolve it distinguishing z>0 from z<0 such as:
DSolve[(1 - b*z)*f[z]/a == f''[z], f[z], z>0]
But I still does not work.
Maybe adding a domain explicitly would help but I can't find a way to do so.
Does anyone has any idea how do do such things?
Thank you for your help and time
You can pass your assumptions on to the solver with Refine:
Refine[DSolve[(1 - b*Abs[z])*f[z]/a == f''[z], f[z], z], z > 0]
gives
{{f[z] -> AiryAi[(1/a - (b z)/a)/(-(b/a))^(2/3)] C[1] + AiryBi[(1/a - (b z)/a)/(-(b/a))^(2/3)] C[2]}}

Calculating Omega for algorithm efficiency

I am having trouble understanding calculating the efficiency of an algorithm. Here is one of my problems. Can someone help explain what method is used for figuring this out? The book is very confusing and does not spend a lot of time on this.
Find the appropriate Ω relationship between the functions n^3 and 3n^3 - 2n2 + 2 and find the constants c and n0
I know that there isnt much difference between n^3 and 3n^3 but I am not sure how to find the constants c and n0;
The functions n3 and 3n3 - 2n2 + 2 are actually Θ of one another, meaning that they grow at the same rates. It should be possible to lower-bound each of the functions with the other.
In the first direction, notice that
3n3 - 2n2 + 2
≥ 3n3 - 2n2
≥ 3n3 - 2n3
= n3
Therefore, if you pick c = 1 and n0 = 0, then we get that for any n ≥ n0 that 3n3 - 2n2 + 2 ≥ cn3, so 3n3 - 2n2 + 2 = Ω(n3)
I'll leave the reverse direction as the proverbial Exercise to the Reader. :-)
Hope this helps!

Computation of numerical integral involving convolution

I have to solve the following convolution related numerical integration problem in R or perhaps computer algebra system like Maxima.
Integral[({k(y)-l(y)}^2)dy]
where
k(.) is the pdf of a standard normal distribution
l(y)=integral[k(z)*k(z+y)dz] (standard convolution)
z and y are scalars
The domain of y is -inf to +inf.
The integral in function l(.) is an indefinite integral. Do I need to add any additional assumption on z to obtain this?
Thank you.
Here is a symbolic solution from Mathematica:
R does not do symbolic integration, just numerical integration. There is the Ryacas package which intefaces with Yacas, a symbolic math program that may help.
See the distr package for possible help with the convolution parts (it will do the convolutions, I just don't know if the result will be integrable symbolicly).
You can numerically integrate the convolutions from distr using the integrate function, but all the parameters need to be specified as numbers not variables.
For the record, here is the same problem solved with Maxima 5.26.0.
(%i2) k(u):=exp(-(1/2)*u^2)/sqrt(2*%pi) $
(%i3) integrate (k(x) * k(y + x), x, minf, inf);
(%o3) %e^-(y^2/4)/(2*sqrt(%pi))
(%i4) l(y) := ''%;
(%o4) l(y):=%e^-(y^2/4)/(2*sqrt(%pi))
(%i5) integrate ((k(y) - l(y))^2, y, minf, inf);
(%o5) ((sqrt(2)+2)*sqrt(3)-2^(5/2))/(4*sqrt(3)*sqrt(%pi))
(%i6) float (%);
(%o6) .02090706601281356
Sorry for the late reply. Leaving this here in case someone finds it by searching.
I try to do something similar in matlab, where I convolute two random (Rayleigh distributed) variables. The result of fz_fun is equal to fy_fun, I don't know why. Maybe some here knows it?
sigma1 = 0.45;
sigma2 = 0.29;
fx_fun =#(x) [0*x(x<0) , (x(x>=0)./sigma1^2).*exp(-0.5*(x(x>=0)./sigma1).^2)];
fy_fun =#(y) [0*y(y<0) , (y(y>=0)./sigma2^2).*exp(-0.5*(y(y>=0)./sigma2).^2)];
% Rayleigh distribution of random var X,Y:
step = 0.1;
x= -2:step:3;
y= -2:step:3;
%% Convolution:
z= y;
fz = zeros(size(y));
for i = 1:length(y)
fz_fun(i) = integral(#(z) fy_fun(y(i)).*fx_fun(z-y(i)),0,Inf); % probability density of random variable z= x+y
end

Resources