I have a simple formula for which I want to solve. Assuming all variables other than x are known, I am trying to solve for x by the following folmula: x = [(c-a)/a]^(1/b)
The initial equation was: a * x^b - a = c, and that was my way for solving for x.
Below is a snippet of my code.
a = 5000
b = 5
c = 562
x = ((c-a)/a)**(1/b)
But for some reason it cannot handle it. Any suggestions?
I think the correct formula is:
x = ((c+a)/a)**(1/b)
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.")
}
}
So I have been trying to decipher some code but have hit a roadblock.
can someone please explain to me the what is being done to P$L to get P$HY to get column Y.
I need to understand Functionally (visually how the data frame changes) and from a Mathematical point of view.
Thanks in advance
# create sample data frame
L <- c(15,12,9,6,3,0)
HY <- c(0,0.106,0.277,0.641,0.907,1)
P <- data.frame(L,Y)
# constants
d <- 5
# THIS IS THE PART THAT I DO NOT UNDERSTAND!!
Y <- lm(P$HY ~ poly(P$L, d))
So it re-iterate the question I´m trying to figure out, mathematically and functionally, what Y <- lm(HY ~ poly(L, d)) is doing.
You are building a linear model with HY as the dependent variable and L as the independent variable using a polynomial of degree 5 for L, so 5 terms for this variable. You are saving this model in the variable Y.
ClustOfVar is a package for clustering columns.
mtcars[] = lapply(mtcars,as.character)
fit = ClustOfVar::hclustvar(X.quali = mtcars)
labels = cutree(fit,h=0.5)
But when I cutree for some fits, I get the following message.
Warning: Error in cutree: the 'height' component of 'tree' is not sorted (increasingly)
The data on which this problem occurs is both private and big. The fit is generated successfully. I will try my best to find a reproducible data example but if you have met this kind of problem before, please let me know how to deal with it.
With certain linkage methods, it can happen that there is a non-monotonicty in the tree. Then this error occurs. If I'm not mistaken, centroid linkage is particularly prone to this.
The problem looks like this: C is created from A and B. Subtree A is created at height x. Subtree B is created at height y. Usually A and B would merge at a height such that z > x and z > y. But with some linkages, this property may be violated and e.g. z < x. Now if we want to cut the tree at height h with z < h < x, then we have the contradiction that subtree C should be merged (becaude z < h) but A should be split (because h < x) - but A is part of C.
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]}}