# code • ### Question

• i have the equation

f(x(i),y(j))=(x(i)^2-x(i))+y(i)

where x(i)=i*h and h=0.1

and y(i)=i*h

by using

for i=1 to 5....next

and for j=1 to 5....next

i want to write that in visual basic . help me plz

Wednesday, March 7, 2018 11:21 AM

### All replies

• Hello,

Before anyone works with you on this, can you show us what you have tried so far using the code button. Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
VB Forums - moderator Wednesday, March 7, 2018 11:47 AM
• I think in your equation the y(i) should be y(j)?

The first thing you should do is reduce the equations.

You have:

f(x(i),y(j))=(x(i)^2-x(i))+y(j)

say     f = (x(i) ^ 2 - x(i)) + y(j)

where
x(i) = i * h
y(j) = j * h
h= 0.1

Is that correct?

therefore:

x = 0.1i
y = 0.1j

now substitute:

f = ((0.1 * i) ^ 2 - (0.1 * i)) + (0.1 * j)

Then you need to write the code and display the result somehow. I used a textbox: So give it a go and then show us your code and exactly where you have questions if any.

Wednesday, March 7, 2018 1:17 PM
• Do you just want to know how to write that function in VB?

```'f(x(i),y(j))=(x(i)^2-x(i))+y(j)
Private Function DoExpression(x() As Double, y() As Double, i As Integer, j As Integer) As Double
Return (x(i) ^ 2 - x(i)) + y(j)
End Function
```

Then use it with something like:

```Dim xValues() As Double
Dim yValues() As Double
Dim i, j As Integer

Dim result = DoExpression(xValues, yValues, i, j)
```

Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

Wednesday, March 7, 2018 7:57 PM
• Hi emanhh,

The following code is to write the equation with vb.net.

```   Dim h As Double = 0.1
Dim xvalue As Double
Dim yvalue As Double
Dim xyvalue As Double
For i As Integer = 1 To 5
For j As Integer = 1 To 5
xvalue = i * h
yvalue = j * h
xyvalue = xvalue ^ 2 - xvalue + yvalue
Console.WriteLine(xyvalue)
Next
Next```

Best Regards,

Cherry

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

• Proposed as answer by Monday, March 19, 2018 9:33 AM
Thursday, March 8, 2018 2:34 AM