I have this formula to solve. enter image description here
And here is my code that outputs an error in the formula.
Private Sub CommandButton6_Click()
Dim Z As String
Dim X As Double, Y As Double
Z = InputBox("Input number X!", "Inputing number X"): X = Val(Z)
Y = Sqr(2 * ((X - 2) ^ 2) * ((8 - X) - 1)^1/3
MsgBox ("Y =" Str(Y))
End Sub
CodePudding user response:
Taking into account when we get negative result under the root
Y = (2 * ((X - 2) ^ 2) * (8 - X) - 1)
If Y >= 0 Then
Y = Y ^ (1 / 3)
Else
Y = -(Abs(Y) ^ (1 / 3))
End If
This is the answer for your 2nd question in comments
Y = (2 * (X ^ 2) * (X - 6))
If Y >= 0 Then
Y = 1 (Y ^ (1 / 3))
Else
Y = 1 - (Abs(Y) ^ (1 / 3))
End If
You can add round if you want, but haven't seen any rounding used in the image link.