Qbasic GOTO to a line with Apostophe - goto

I'm trying to "convert" an old program in QBasic to Java.
I have a problem while debugging and I think is related to this GOTO statement.
I know that a line with an apostrophe is ignored but in this case the statement GOTO targets that line. Is ignored the first time and after with the GOTO statement is not?And the apostrophe concerns only the variable R12 and X12 or also R22,X22?
This is the .BAS file :)
*
4010 'R12 = R2MA + ((R2A * R2M * (R2A + R2M) + S ^ 2 * (R2A * X2M ^ 2 + R2M * X2A ^ 2)) / ((R2A + R2M) ^ 2 + S ^ 2 * (X2A + X2M) ^ 2))
4014 'X12 = X2D + ((R2A ^ 2 * X2M + R2M ^ 2 * X2A + S ^ 2 * X2A * X2M * (X2A + X2M)) / ((R2A + R2M) ^ 2 + S ^ 2 * (X2A + X2M) ^ 2))
R22 = ((R2A * XMMU ^ 2 + R2M * XAVVMU ^ 2) * S ^ 2 + R2A * R2M * RT2) / (RT2 ^ 2 + S ^ 2 * XT2 ^ 2)
X22 = (X2A * (R2M ^ 2 + S ^ 2 * X2M ^ 2) + X2M * (R2A ^ 2 + S ^ 2 * X2A ^ 2) + 2 * X2AVM * (R2A * R2M - S ^ 2 * X2AVM * XT2)) / (RT2 ^ 2 + S ^ 2 * XT2 ^ 2)
X22 = X22 + X2D
R22 = R22 / ZUN: X22 = X22 / ZUN
4016 A1 = R22 * E1 ^ 2 / (P2 * X22 ^ 2 + R22 * E1 ^ 2)
4020 S = .5 * A1 - SQR(A1 * (.25 * A1 - R22 * P2 / E1 ^ 2))
4030 G1 = (PFE / (3 * (VF * (FR / 100)) ^ 2)) * ZUN
4040 A2 = (R22 / S) ^ 2 + X22 ^ 2: B2 = R22 / (S * A2): C2 = X22 / A2: D2 = B2 + G1
4050 E2 = C2 + B1: F2 = D2 ^ 2 + E2 ^ 2: G2 = D2 / F2: H2 = E2 / F2: Z2 = SQR(G2 ^ 2 + H2 ^ 2)
4060 I2 = G2 + R11: L = H2 + X11: ZTOT = SQR(I2 ^ 2 + L ^ 2)
4070 I1 = 1 / ZTOT
4080 E3 = I1 * Z2
4090 IF ABS(E1 - E3) > P0 THEN 5800
.
.
.
5800 E1 = (E1 + E3) / 2
5810 GOTO 4010
*

This sure is an odd way to write a QBasic program, usually you either number all of the lines or none of them. You can run a small test program to see how QB handles GOTO in this case. So something like this:
10 I = 0
20 'PRINT "Test line 20"
30 'PRINT "Test line 30
PRINT "Test line 40"
PRINT "Test line 50"
60 PRINT "Test line 60"
70 I = I + 1
80 IF (I <= 1) GOTO 20
90 PRINT "THE END"
I tried this in QB4.5 and the output is this:
Test line 40
Test line 50
Test line 60
Test line 40
Test line 50
Test line 60
THE END
The GOTO statement works as normal but the contents of lines 20 and 30 are not executed, it is treated as comment. So to answer your question, in your case the lines with R12 = .. and X12 = .. will be ignored and not executed, and the lines with R22 = .. and X22 = .. etc. are processed as normal.

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!

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)

Creating matrix in loop using a function in R

I have a function to use in R
TV <- function(v1,v2) {
write.csv(log(2 ^ (-1 / 2) * exp(-1 / 2) * beta(1 / 2, v1 / 2) / gamma(1 / 2)) - log(2 ^ (-1 / 2) * exp(-1 / 2) * beta(1 / 2, v2 / 2) / gamma(1 / 2)) + (v1 + 1) * digamma(v1 / 2 + 1 / 2) / 2 + (-1 - v2) * digamma(v2 / 2 + 1 / 2) / 2 + (-1 - v1) * digamma(v1 / 2) / 2 + (v2 + 1) * digamma(v2 / 2) / 2 + 0.5e0 * log(v1 / v2),"write.csv")
}
as you can see the input variables are v1 and v2.
if i give v1=1:10 and v2=1
i get single vector like this
result for v1=1:10 and v2=1.
what i need is a matrix output. for v1=1:10 to v2=1:10. i.e as 10x10 matrix.
how can i do it using R
Try this:
write.csv(outer(1:10, 1:10, FUN=function(v1,v2)log(2 ^ (-1 / 2) * exp(-1 / 2) * beta(1 / 2, v1 / 2) / gamma(1 / 2)) -
log(2 ^ (-1 / 2) * exp(-1 / 2) * beta(1 / 2, v2 / 2) / gamma(1 / 2)) + (v1 + 1) * digamma(v1 / 2 + 1 / 2) / 2 +
(-1 - v2) * digamma(v2 / 2 + 1 / 2) / 2 + (-1 - v1) * digamma(v1 / 2) / 2 + (v2 + 1) * digamma(v2 / 2) / 2 + 0.5e0 * log(v1 / v2)), 'write.csv')

Appropriately using go to algorithm in R

I have an algorithm written as follows but I need to write that code into R. I have included the algorithm and the R code. I am not sure if that is represented well enough. To write the R code in the sequential order is not straight forward. I am sorry for not providing all the values of the variables here. I am not sure of the output yet which is the reason I am unable to show the required. It is more of a theoretical question.
Algorithm
VBDMAX = (va - VG) * 0.79 * (dep / D) ^ -1.21
VBOWMAX = -0.7 * VBDMAX
VBOWX = 0
' SKIP BOW IF -10D<X<15D OR OUTSIDE EDGE OF BARGES
If Y > B / 2 Then GoTo 200
If X < -10 * D Then GoTo 200
If X >= 15 * D Then GoTo 200
VBOWX = X * VBOWMAX / (10 * D) + VBOWMAX
If X <= 0 Then GoTo 200
VBOWX = X * (VBDMAX - VBOWMAX) / (5 * D) + VBOWMAX
If X <= 5 * D Then GoTo 200
VBOWX = -X * VBDMAX / (10 * D) + 15 * VBDMAX / 10
200 ' end bow
This is the R code that I have written
VBDMAX = (va - VG) * 0.79 * (dep / D) ^ -1.21
VBOWMAX = -0.7 * VBDMAX
VBOWX = 0
# SKIP BOW IF -10D<X<15D OR OUTSIDE EDGE OF BARGES
VBOWX <- ifelse ((Y>B/2 | X < -10*D | X>=15*D), 0,X*VBOWMAX/(10*D)+VBOWMAX)
VBOWX <- ifelse (X<=0 , X * (VBDMAX - VBOWMAX) / (5 * D) + VBOWMAX,
ifelse(x <=5*D, -X * VBDMAX / (10 * D) + 15 * VBDMAX / 10))
You can use ifelse constructs but you will need to nest those:
VBDMAX = (va - VG) * 0.79 * (dep / D) ^ -1.21
VBOWMAX = -0.7 * VBDMAX
VBOWX =
ifelse(Y > B / 2 || X < -10 * D || X >= 15 * D,
0,
ifelse(X <= 0,
X * VBOWX / (10 * D) + VBOWMAX,
ifelse(X <= 5 * D,
X * (VBDMAX - VBOWMAX) / (5 * D) + VBOWMAX,
-X * VBDMAX / (10 * D) + 15 * VBDMAX / 10
)
)
)
Understanding your question as how to translate "goto" statements to R, there are the following posibilities (if really needed) besides or in adjunction to the (often more appropriate) if/ifelse constructions as you already did:
a) entire code (for severe errors or if problem is solved): if (condition) stop("explain why...") or stopifnot(condition)
b) from within loops: see next and break
c) from within function: if (condition) return(), stopping the function here

Resources