Mathematica DSolve diff. equation over a particular domain - math

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]}}

Related

How to solve an equation y=ax^2+bx+c when x is unknown and y known

I have this equation:
y = -0.00248793*x^2+20.77173764*x-371.01805798
And I would like to obtain the result of the equation when I give "y" numbers,
edited explanation 2/06/20:
I want to add a vector as my "y", and receive an output of one vector also.
This problem is a biological one, in which I performed citokine bead array (CBA) and I stablished a reference curve which is sinusoidal.
after stablishing the degree of the equation making the following:
fitil6_1=lm(Standards$`IL6 median`~poly(concentration,1,raw=TRUE))
fitil6_2=lm(Standards$`IL6 median`~poly(concentration,2,raw=TRUE))
fitil6_3=lm(Standards$`IL6 median`~poly(concentration,3,raw=TRUE))
fitil6_4=lm(Standards$`IL6 median`~poly(concentration,4,raw=TRUE))
lines(concentration,predict(fitil6_1,data.frame(x=concentration)),col="red")
lines(concentration,predict(fitil6_2,data.frame(x=concentration)),col="green")
lines(concentration,predict(fitil6_3,data.frame(x=concentration)),col="blue")
lines(concentration,predict(fitil6_4,data.frame(x=concentration)),col="purple)
legend(20,40000,legend=c("de grau 1","de grau 2","de grau 3","de grau 4"),lty=1,col=c("red","green","blue","purple"))
I have chosen the degree 2 formula as it fits better to my dots for this cytokine (and most cytokines in this study)
So when I make
coef(fitil6_2)
(Intercept) poly(concentration, 2, raw = TRUE)1 poly(concentration, 2, raw = TRUE)2
-8.262381e+02 2.371377e+01 -2.847135e-03
I receive that output and then I am able to build the formula (in this case):
y=-2.847135e-03 *x^2+2.371377e+01*x-8.262381e+02
but as my independent value is what I know is pretty difficult to isolate x!
(end of the editing)
I have tried many things like making function(x,y) but when you specify this you need to give a number of y, so really I am litlle bit lost!
Thank you
As #Dave2e said, you can solve this particular example by algebra. But you might need a programmatic solution, or you might be using the quadratic as an easy example. in which case...
Rewrite your problem as "what value of y satisfies -0.00248793*x^2+20.77173764*x-371.01805798 - y = 0?".
There are plenty of ways to find the zeroes of a function. That's what you've turned your problem into. Suppose your "known value of y" is 10...
f <- function(x, y) {
-0.00248793*x^2+20.77173764*x-371.01805798 - y
}
answer <- stats::uniroot(f, interval=c(0, 50), y=10)
# Check we've got the right answer
f(answer$root, 10)
Giving
[1] -1.186322e-10
Using this method, you do need to find/guess a range within which the answer might lie. That's the purpose of the interval=c(0.50) part of the call to uniroot. You can read the online help for more information about the value returned by uniroot and things you might want to look out for.
Thank you for all who answered I have just started in this page, this worked for me:
isolating "y" and then making a function with the quadratic formula to x:
delta<-function(y,a,b,c)
{k=(-b+sqrt(b^2-4*a*(c-y)))/(2*a)
print(k)
}
delta(citoquines_valero$`IFNg median`,-1.957128e-03,1.665741e+01,-7.522327e+02)
#I will use that one as a provisional solution.
#I have also been told to use this, but is not working properly:
result <- function(y,a,b,c){
# Constructing delta
delta<-function(y,a,b,c){
b^2-4*a*(c-y)
}
if(delta(a,b,d) > 0){ # first case D>0
x_1 = (-b+sqrt(delta(y,a,b,c)))/(2*a)
x_2 = (-b-sqrt(delta(y,a,b,c)))/(2*a)
if (x_1 >= 0) {
print(x_1)
else if (x_2 >= 0){
print(x_2)
}
}
print(result)
else if(delta(a,b,d) == 0){ # second case D=0
x = -b/(2*a); return(x)
}
else {"There are no real roots."}; # third case D<0```
return("There are no real roots.")
}
}

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.

Find root in sagemath

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.

Optimizing for global minimum

I am attempting to use optimize() to find the minimum value of n for the following function (Clopper-Pearson lower bound):
f <- function (n, p=0.5)
(1 + (n - p*n + 1) /
(p*n*qf(p= .025, df1= 2*p, df2= 2*(n - p + 1))))^-1
And here is how I attempted to optimize it:
n_clop <- optimize(f.1, c(300,400), maximum = FALSE, p=0.5)
n_clop
I did this over the interval [300,400] because I suspect the value to be between within it but ultimately I would like to do the optimization between 0 and infinity. It seems that this command is producing a local minimum because no matter the interval it produces the lower bound of that interval as the minimum - which is not what I suspect from clopper-pearson. So, my two questions are how to properly find a global minimum in R and how to so over any interval?
I've very briefly looked over the Wikipedia page you linked and don't see any obvious typos in your formula (although I feel like it should be 0.975=1-alpha/2 rather than 0.025=alpha/2?). However, evaluating the function you've coded over a very broad scale suggests that there are no local minima that are messing you up. My strong guess would be that either your logic is wrong (i.e., n->0 is really the right answer) or that you haven't coded what you think you're coding, due to a typo (possibly in the Wikipedia article, although that seems unlikely) or a thinko.
f <- function (n, p=0.5)
(1 + (n - p*n + 1) /
(p*n*qf(p= .025, df1= 2*p, df2= 2*(n - p + 1))))^-1
Confirm that you're getting the right answer for the interval you chose:
curve(f(x),c(300,400))
Evaluating over a broad range (n=0.00001 to 1000000):
curve(f(10^x),c(-5,7))
As #MrFlick suggests, global optimization is hard. You could start with optim(...method="SANN") but the best answer is definitely case-specific.

DSolve with conditions in Mathematica

I would like to solve this equation in Mathematica :
DSolve[{p'[r] == 1/((r^2)*(((R - S)/(R^3)) - (1/(r^2)*(1 - S/r)))^(1/2))}, p[r], r]
but I have some supplementary conditions:
S is a strictly positive real
R > 3*sqrt(3)*S/2
I want the solution over the interval r in ]R, +infinity]
I am a beginner with Mathematica so how to specify these conditions ?
Your existing code appears to produce a solution (albeit large) on Mathematica 8
sol = DSolve[{p'[r] ==
1/((r^2)*(((R - S)/(R^3)) - (1/(r^2)*(1 - S/r)))^(1/2))}, p[r], r]
You can add the additional constraints on the solution, as part of the simplification. It doesn't appear to make a significant difference. Were you expecting something different?
Simplify[sol, {S, R} \[Element] Reals && S > 0 && R > 3*sqrt (3)*S/2]
Minor Correction
FullSimplify[sol, {S, R} \[Element] Reals && S > 0 && R > 3*sqrt (3)*S/2]
Appears to simplify some of the terms, but only a little.

Resources