## Some ideas? No actual code needed...

## Some ideas? No actual code needed...

(OP)

Hello all,

I have this simple numerical problem to solve, for which I know what to do (done it in 1D) and I am only asking which -in your opinion- would be the best way to arrange and present my data in order to plot them using gnuplot or similar. A brief description of the problem follows:

A nxn grid will be created, say 41 points on x axis and 41 points on y axis. The initial values for our function will be stored in a 41 x 2 array (call it u(i,j)). Conditions applied on x,y axes values will apply on u. Thus we will have the x,y coordinates and two columns of "zeros" for the corresponding u(i,j) values. Then the numerical scheme will be applied to solve the problem. Something like: u(i,j) = 2*u(i-1,j-1) +.... etc.

My first thought is to create a single matrix with four columns: x, y, u(i), u(j).Then store the initial values and write the code to solve the problem. Is that OK? Would it be better to have separate arrays to store the values for x,y and u?

I sincerely hope that the description of the problem does not cause any confusion. If so, please ask for clarifications.

Thank you in advance for your assistance.

I have this simple numerical problem to solve, for which I know what to do (done it in 1D) and I am only asking which -in your opinion- would be the best way to arrange and present my data in order to plot them using gnuplot or similar. A brief description of the problem follows:

A nxn grid will be created, say 41 points on x axis and 41 points on y axis. The initial values for our function will be stored in a 41 x 2 array (call it u(i,j)). Conditions applied on x,y axes values will apply on u. Thus we will have the x,y coordinates and two columns of "zeros" for the corresponding u(i,j) values. Then the numerical scheme will be applied to solve the problem. Something like: u(i,j) = 2*u(i-1,j-1) +.... etc.

My first thought is to create a single matrix with four columns: x, y, u(i), u(j).Then store the initial values and write the code to solve the problem. Is that OK? Would it be better to have separate arrays to store the values for x,y and u?

I sincerely hope that the description of the problem does not cause any confusion. If so, please ask for clarifications.

Thank you in advance for your assistance.

## RE: Some ideas? No actual code needed...

what's that about a matrix with four columns with x, y, u(i), u(j)? That does not make sense, does it? I didn't think there was such thing as a separate u(i) or u(j)...the only thing I thought existed was u(i,j)...in other words, you have 41 x-values and 41 y-values and you have one u value per every combination of x and y...meaning, u is a 2D matrix of 41x41 and can be plotted as a surface (the z height) on top of the x-y plane.

Anyway, that's what I thought.

## RE: Some ideas? No actual code needed...

TTFN

I can do absolutely anything. I'm an expert!

FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers

## RE: Some ideas? No actual code needed...

My take would be: always think about the scalability and performance bottlenecks and try to consider cases you that don't immediately spring to mind. What happens if the matrix is symmetric. You can compute half the terms and then just use pointers for the lower triangle into the upper triangle. What happens if the matrix is sparse, or block diagonal. If you are going to handle huge data, you might not actually want to store zeros. Keeping separate vectors would allow packed methods to allocate only enough memory for the non-zero terms.

On the other hand, if the problem is always going to be of the order of 40x40, use the method which is easiest to maintain. When you look at your code in 6 months, will you understand what you did?

Just a few thoughts.

## RE: Some ideas? No actual code needed...

Indeed, it is a surface plot, so there will be simply an x value, a y value and the u(i,j) value (the z value in a 3D cartesian coordinate system as correctly pointed).

Thank you for sharing your thoughts with me and sorry for the confusion caused.

## RE: Some ideas? No actual code needed...

Here is something easy for you: Since my x (or y) values have an non integer step for the do loop and this is not always acceptable, I have used the following code to fill my x values (aka DO-WHILE loop):

## CODE --> 95

Any other (faster) suggestions?

Thanks in advance!

## RE: Some ideas? No actual code needed...

You know EXACTLY how many iterations this will take, and if you're filling with zeros, you don't care what the x value is, so why calculate it? You should look up FOR loops in your textbook or on the internet

TTFN

I can do absolutely anything. I'm an expert!

FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers

## RE: Some ideas? No actual code needed...

No, this is absolutely

NOTa school/university/college etc. project. I am a just self learner. Nothing more, nothing less. The problem I am studying has an initial condition for u (or whatever you call it) depending on x,y values. Thus, I am filling it with zeros and then based on explicitely declared limits on x,y some values of u will change. That will be my IC which will be "feed" to the numerical solution to proceed with the calculations. I hope this answers your question. Maybe (I repeat maybe) the fact that my code had u (again!) for storing the x values confused you.## RE: Some ideas? No actual code needed...

Your code should look like:

do i=0,40

do j=0,40

u(i,j)=0

end do

end do

There should be no calculations needed; you already know how big the array is and you know what value to put into.

TTFN

I can do absolutely anything. I'm an expert!

FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers

## RE: Some ideas? No actual code needed...

I do not disagree with you. Your code is fine if you want a step size for i,j of one (or an integer). But what if you want to go from 0 to 40 with a step size of say 0.5?

Based on the above conversation (even with my "blurry" description of the problem) I have a clear view of what to do, therefore there is no need to continue this thread. In any case thank you and the other contributors for your interest.

## RE: Some ideas? No actual code needed...

I can do absolutely anything. I'm an expert!

FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers