|
-
April 21st, 2011, 09:46 PM
#1
creating array with size determined by user input?
So in MATLAB, I can create a matrix with a size determined by the user input, such as below:
T=input('Number of data points for time variable? ');
N = input('Number of grid points N? ');
Temp = zeros(N,T);
So that if I enter 5 for T and 4 for N, then Temp will be a 4 by 5 matrix. But I'm having trouble doing the same thing for C++. I defined T and N as variables, such as like this
int T;
cout<<"Number of data points for time variable? ";
cin>>T;
and similarly for N.. But then I tried writing
float Temp[][];
or
float Temp[N][T]
then I got errors. How do I fix this?
On a side note, are there any computational physicists here? Are there any good websites that have relatively simple codes for comp physics problems? I'm been looking for websites that have codes with problems that I could work on but haven't found many. The code I wrote above was to solve the Heat Equation numerically.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|