Hello I have this question to perform it on VBA the question is :
Develop a VBA programme that can derive the exact solutions of a differential equation of the form:
dy / dx + xy = xy ^ 3
The user should be able to input the values for y_boundary, x_boundary (initial condition) as well as an input value x in order for your programme to calculate y.
My code is below
Sub Button1_Click()
Dim x As Double, y As Double, h As Double 'declare variables x, y and h
x = InputBox("Input initial condition x=") 'ask user for initial conditinn value of x
y = InputBox("Input initial condition y=") 'ask user for initial condition value of y
h = InputBox("Input the change in x; h=") 'ask user for the value of change in x; h
Range("A5").Value = x 'set the cell A5 to x
Range("B5").Value = y 'set the cell B5 to y
Range("B2").Value = h 'set the cell B2 to h
End Sub
Function cons1(h As Double, Xn As Double, Yn As Double) As Double
cons1 = h * ((Xn * Yn ^ 3) - (Xn * Yn)) 'calculates K1
End Function
Function cons2(h As Double, Xn As Double, Yn As Double, cons1 As Double) As Double
cons2 = h * ((Xn + h / 2) * (Yn + cons1 / 2) ^ 3 - (Xn + h / 2) * (Yn + cons1 / 2)) 'calculates K2
End Function
Function cons3(h As Double, Xn As Double, Yn As Double, cons2 As Double) As Double
cons3 = h * ((Xn + h / 2) * (Yn + cons2 / 2) ^ 3 - (Xn + h / 2) * (Yn + cons2 / 2)) 'calculates K3
End Function
Function cons4(h As Double, Xn As Double, Yn As Double, cons3 As Double) As Double
cons4 = h * ((Xn + h) * (Yn + cons3) ^ 3 - (Xn + h) * (Yn + cons3)) 'calculates K4
End Function
Function YRK(cons1 As Double, cons2 As Double, cons3 As Double, cons4 As Double, Yn As Double) As Double
YRK = Yn + 1 / 6 * (cons1 + (2 * cons2) + (2 * cons3) + cons4) 'calculates Yn+1 for Runge-Kutta method
End Function
Function f(Xn As Double, Yn As Double) As Double
f = ((Xn * Yn ^ 3) - (Xn * Yn)) 'calculates f(Xn,Yn)
End Function
Function Yeuller(h As Double, Yn As Double, f As Double) As Double
Yeuller = Yn + (h * f) 'calculates Yn+1 for Euller method
End Function
Function Yeuller_cauchy(h As Double, Yn As Double, Xn As Double) As Double
Yeuller_cauchy = Yn + (h * ((Xn * Yn ^ 3) - (Xn * Yn))) 'calculates Yn+1 for Euller-Cauchy Method
End Function
Screenshot (153).pngScreenshot (154).png
PLEASE I REALLY NEED HELP WITH THIS ASAP. TELL ME WHAT I AM DOING WRONG, I APPRECIATE ANY KIND OF HELP.
THANK YOU IN ADVANCE
Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #1 requires good titles. "Programming using VBA" didn't tell us anything about your specific question. I have updated it for you this time because you are a new member.--6StringJazzer
Bookmarks