How to rearrange the complex algebraic equation in R? - r

The nonlinear equation is following,A,B,C,D,E are know. I want to rearrange the formation of the equation. Let the X at the left of equation,and let other parameters all at the right of equation. such as X= A*B/D+E^2/C
Is there are some software to do this?such as R.

Try this -- ignore the warnings from that XML package that have started recently.
library(Ryacas)
A <- Sym("A")
B <- Sym("B")
C <- Sym("C")
D <- Sym("D")
E <- Sym("E")
X <- Sym("X")
Solve(E == A * B * (X + C) / (A + B * (X + C)) - A * B * (X + D + C) / (A + B * (X + D + C)), X)
giving:
expression(list(X == (root((2 * (E * A * B) + (2 * (E * B^2 *
C) + E * B^2 * D))^2 - 4 * (E * B^2 * (E * A^2 + (2 * (E *
A * B * C) + E * A * B * D) + (E * B^2 * C^2 + E * B^2 *
C * D) + A^2 * B * D)), 2) - (2 * (E * A * B) + (2 * (E *
B^2 * C) + E * B^2 * D)))/(2 * (E * B^2)), X == -(2 * (E *
A * B) + (2 * (E * B^2 * C) + E * B^2 * D) + root((2 * (E *
A * B) + (2 * (E * B^2 * C) + E * B^2 * D))^2 - 4 * (E *
B^2 * (E * A^2 + (2 * (E * A * B * C) + E * A * B * D) +
(E * B^2 * C^2 + E * B^2 * C * D) + A^2 * B * D)), 2))/(2 *
(E * B^2))))
An alternative to the above if you have specific values for A, B, C, D, E would be to numerically solve it using, for example, uniroot.

Related

plotting Hamid Naderi Yeganehs parrot using ggplot

I am a) new to stackoverflow and b) an advanced beginner to R ;-)
i saw some bird artworks of Yeganeh with the associated functions in the web Drawing Birds in Flight With Mathematics and wanted to reproduce them in R to experiment a bit with colouring and so on.
However, while this one yielded a quite good result:
k <- 1:9830
X <- function(k) {
sin(pi * k / 20000) ^ 12 *
(0.5 * cos(31 * pi * k / 10000) ^ 16 *
sin(6 * pi * k / 10000) + (1 / 6 * sin(31 * pi * k / 10000)) ^ 20) +
3 * k / 20000 + cos(31 * pi * k / 10000) ^ 6 *
sin((pi / 2) * ((k - 10000) / 10000) ^ 7 - pi / 5)
}
Y <- function(k) {
-9 / 4 * cos(31 * pi * k / 10000) ^ 6 *
cos(pi / 2 * ((k - 10000) / 10000) ^ 7 - pi / 5) *
(2 / 3 + (sin(pi * k / 20000) * sin(3 * pi * k / 20000)) ^ 6) +
3 / 4 * cos(3 * pi * ((k - 10000) / 100000)) ^ 10 *
cos(9 * pi * ((k - 10000) / 100000)) ^ 10 *
cos(36 * pi * ((k - 10000) / 100000)) ^ 14 +
7 / 10 * ((k - 10000) / 10000) ^ 2
}
R <- function(k) {
sin(pi * k / 20000) ^ 10 *
(1 / 4 * cos(31 * pi * k / 10000 + 25 * pi / 32) ^ 20 +
1 / 20 * cos(31 * pi * k / 10000) ^ 2) +
1 / 30 * (3 / 2 - cos(62 * pi * k / 10000) ^ 2)
}
bird <- data.frame(x = X(k), y = Y(k), r = R(k))
library(tidyverse)
library(ggforce)
q <- ggplot() +
geom_circle(aes(x0 = x, y0 = y, r = r),
data = bird,
n = 30) +
coord_fixed() +
theme_void()
the following code yielded some weird result which should basically be related to the difference in the function. (x-A(k))+(y-B(k))=(R(k)) for the parrot below, whlie the bird above "simply" consisted of the k-th circle (X(k), Y(k)) and the radius of the k-th circle R(k)
k <- -10000:10000
A <- function(k) {
(3*k/20000)+(cos(37*pi*k/10000))*sin((k/10000)*(3*pi/5))+(9/7)*(cos(37*pi*k/10000))*(cos(pi*k/20000))*sin(pi*k/10000)
}
B <- function(k) {
(-5/4)*(cos(37*pi*k/10000))*cos((k/10000)*(3*pi/5))*(1+3*(cos(pi*k/20000)*cos(3*pi*k/20000)))+(2/3)*(cos(3*pi*k/200000)*cos(9*pi*k/200000)*cos(9*pi*k/100000))
}
R <- function(k) {
(1/32)+(1/15)*(sin(37*pi*k/10000))*((sin(pi*k/10000))+(3/2)*(cos(pi*k/20000)))
}
parrot <- data.frame(a = A(k), b = B(k), r = R(k))
q <- ggplot() +
geom_circle(aes(x0 = a, y0 = b, r = r),
data = parrot,
n=30) +
coord_fixed() +
theme_void()
q
Any help would be very much appreciated. Cartesian coords already applied as [explained here] (https://www.wikiwand.com/en/Hamid_Naderi_Yeganeh). From the visual point of view, it seems like the function is plotted properly but the "view" on it needs to be changed...
Thanks in advance!

R: How to plot use function which find a root

I construct a user-function:
find.c <- function(q) { f <- function(c) {
(log(7.2 + 6 * c * q - 6) * q^6 * (1-q)^(6-6) * factorial(6) / factorial(6) / factorial(6-6)
+ log(7.2 + 6 * c * q - 5) * q^5 * (1-q)^(6-5) * factorial(6) / factorial(5) / factorial(6-5)
+ log(7.2 + 6 * c * q - 4) * q^4 * (1-q)^(6-4) * factorial(6) / factorial(4) / factorial(6-4)
+ log(7.2 + 6 * c * q - 3) * q^3 * (1-q)^(6-3) * factorial(6) / factorial(3) / factorial(6-3)
+ log(7.2 + 6 * c * q - 2) * q^2 * (1-q)^(6-2) * factorial(6) / factorial(2) / factorial(6-2)
+ log(7.2 + 6 * c * q - 1) * q^1 * (1-q)^(6-1) * factorial(6) / factorial(1) / factorial(6-1)
+ log(7.2 + 6 * c * q - 0) * q^0 * (1-q)^(6-0) * factorial(6) / factorial(0) / factorial(6-0)
- log(7.2)
)}
g <- uniroot(f, lower=0, upper=100, extendInt = "yes")[1]
g}
And I tried to plot:
plot(x = seq(0, 1 , 0.001), find.c(x))
then it gives me: "Error in uniroot(f, lower = 0, upper = 100, extendInt = "yes") :
f() values at end points not of opposite sign"
Also is ther any way I can use 'for' loop to simplify this function? I tried may way with for but function inside function makes very complicated.
I agree with #r2evans suggestion, but I think you can restructure this to be simpler without the nested function.
First, define f with both c= and q= as arguments:
f <- function(c,q) {
(log(7.2 + 6 * c * q - 6) * q^6 * (1-q)^(6-6) * factorial(6) / factorial(6) / factorial(6-6)
+ log(7.2 + 6 * c * q - 5) * q^5 * (1-q)^(6-5) * factorial(6) / factorial(5) / factorial(6-5)
+ log(7.2 + 6 * c * q - 4) * q^4 * (1-q)^(6-4) * factorial(6) / factorial(4) / factorial(6-4)
+ log(7.2 + 6 * c * q - 3) * q^3 * (1-q)^(6-3) * factorial(6) / factorial(3) / factorial(6-3)
+ log(7.2 + 6 * c * q - 2) * q^2 * (1-q)^(6-2) * factorial(6) / factorial(2) / factorial(6-2)
+ log(7.2 + 6 * c * q - 1) * q^1 * (1-q)^(6-1) * factorial(6) / factorial(1) / factorial(6-1)
+ log(7.2 + 6 * c * q - 0) * q^0 * (1-q)^(6-0) * factorial(6) / factorial(0) / factorial(6-0)
- log(7.2)
)}
Then loop over each of the q= values:
mapply(function(...) uniroot(...)[[1]],
list(f), q=seq(0,1,0.001), lower=0, upper=100, extendInt="yes")
# [1] 0.000000 1.076564 1.076460 1.076375 1.076291 1.076206 1.076122
# [8] 1.076037 1.075953 1.075868 1.075784 1.075699 1.075614 1.075530
# etc

How to solve following system of equations

I've taken a few measurements of an LC circuit and I need to solve for both L and C based on that. How do I solve this?
2.675e6 = 1 / (2 * pi * sqrt(L * (C + 100e-9))
5.8e6 = 1 / (2 * pi * sqrt(L * C))
You need pencil and paper:
Equation #1
5.8e6 = 1 / (2 * pi * sqrt(L * C))
sqrt(L * C)= 1 / (2 * pi * 5.8e6 )
L*C = 1 / (2 * pi * 5.8e6 )^2
Equation #2
2.675e6 = 1 / (2 * pi * sqrt(L * (C + 100e-9))
sqrt(L * (C + 100e-9))= 1 / ( 2 *pi *2.675e6 )
L * (C + 100e-9) = 1 / ( 2 *pi *2.675e6 )^2
Subtract #1 from #2
L * (C + 100e-9) - L*C = 1 / ( 2 *pi *2.675e6)^2 - 1 / (2 * pi * 5.8e6 )^2
L * 100e-9 = 1 / ( 2 *pi *2.675e6)^2 - 1 / (2 * pi * 5.8e6 )^2
L = 1e7 * (1 / ( 2 *pi *2.675e6)^2 - 1 / (2 * pi * 5.8e6 )^2 )
and than from #1
C = ( 1 / (2 * pi * 5.8e6 )^2 ) / L

How I find the total area of a triangle from the areas of three sections out of six created by concurrent lines one from each vertex?

In this triange:
Given the areas of triangles UPZ ZPW and WPY, how do you calculate the total area?
I've already found the solution from the available submissions at the website. But I want to know how to derive that solution.
cin >> a >> b >> c;
// a is UPZ, b is ZPW, c is WPY
double n = b*(a+b)*(a+b+c);
double d = b*(a+b)-(a*c);
cout << (n / d) ;
Indeed, this question is kind of off topic, it is a geometry problem. The way to find the area of the big triangle UVW is to apply the link between areas and ratioes of lengths of the segments of the triangle UYW and then to apply Menelaus' theorem to derive the ratio
WY/WV which reveals the ratio between the areas of the triangle UYW and UVW.
Let h_p be the length of the height from point P to the edge UW. Then
a = UZ * h_p / 2 and b = ZW * h_p / 2
Thus:
a / b = (UZ * h_p / 2) / (ZW * h_p / 2) = UZ / ZW
Let h_W be the length of the height from point W to the line UY
a + b = Area(WPU) = PU * h_W / 2 and c = YP * h_w / 2
Thus:
c / (a + b) = (YP * h_W / 2) / (PU * h_W / 2) = YP / PU
By Menelaus' theorem for the triangle UWY and the line VZ, with P on VZ, we get:
1 = ( VW / VY ) * ( YP / PU ) * ( UZ / ZW ) = ( VW / WY ) * (c / (a + b)) * (a / b)
so
VY / VW = (c * a) / ( b * (a + b))
and therefore:
WY / VW = 1 - (VY / VW) = 1 - (c*a) / ( b*(a + b)) = (a*b + b^2 - a*c ) / (a*b + b^2)
Let h_U be the length of the height from the point U to the edge VW. Then
Area(UVW) = VW * h_U / 2
and
Area(UYW) = a + b + c = WY * h_U / 2
Hence
Area(UVW) / Area(UYW) = Area(UVW) / (a + b + c) = (VW * h_U / 2) / (WY * h_U / 2) = VW / WY
so
Area(UVW) / Area(UYW) = VW / WY = (a*b + b^2) / (a*b + b^2 - a*c)
Area(UVW) / Area(UYW) = Area(UVW) / (a + b + c) = (a*b + b^2) / (a*b + b^2 - a*c)
Finally, we obtain the formula:
Area(UVW) = (a + b + c) * (a*b + b^2) / (a*b + b^2 - a*c)
Area(UVW) = b * (a + b) * (a + b + c) / (b*(a + b) - a*c)

How to find math variables in dart equation

I need to know how to find an unknown variable in dart to solve a math equation. B is the unknown variable and the known is the known variable.
double B = 0.0;
double known = 1423.0;
known = B -
((B * 0.105 + B * 0.005 + B * 0.055) +
((B - (B * 0.105 + B * 0.005 + B * 0.055)) * 0.16));
I am not aware of any such package to solve equations, but you can simplify the equation itself just like you do in mathematics. Below is such a solution-
known = B -
((B * 0.105 + B * 0.005 + B * 0.055) +
((B - (B * 0.105 + B * 0.005 + B * 0.055)) * 0.16));
known = B -
((B * 0.165) +
((B - (B * 0.165)) * 0.16));
known = B -
((B * 0.165) +
((B * 0.835) * 0.16));
known = B -
((B * 0.165) +
(B * 0.1336));
known = B -
(B * 0.2986);
known = B * 0.7014;
B= known / 0.7014;

Resources