| New Reply |
Matrix help in MatLab, Not the simple matrix!! I have searched, found nothing! |
Share Thread | Thread Tools |
| Feb23-12, 01:54 AM | #1 |
|
|
Matrix help in MatLab, Not the simple matrix!! I have searched, found nothing!
Please help me with this.
I need to code into matlab a function that results in a matrix answer. It is this: phi(i,j)=atan((eta(j)-eta(i))/(zeta(j)-zeta(i)))*180/pi] Here is my code so far: I only have four etas and four zetas. both i and j = 4. With some work I can get a 4x4 matrix but it isn't coded right. It gives me the same answers in rows. It should have a diagonal line of zero's from top left to bottom right because that is where i=j And I need to be able to change N to 250 so it needs to be easy to write for large N's Thank you for your help! |
| Feb23-12, 03:20 AM | #2 |
|
|
Something is wrong with MatLab. Both my copy and the one at school. I have been using it only for a day or so and I have found a big bug.
When I restart MatLab, my code that was working just before quitting wont work and will get error. All I have to do is cut it from the file, run the file, then put it back in and presto. No error. What a complete waste of time. Anyways, I constructed my matrix using this: phi(i,j)=atan2((eta(j)-eta(i)),(zeta(j)-zeta(i)))*180/pi; And right above that I have j=1:4 My matrix looks like this: 0 -45.0000 -90.0000 -135.0000 135.0000 0 -135.0000 -180.0000 90.0000 45.0000 0 135.0000 45.0000 0.0000 -45.0000 0 Which is basically correct BUT! Because of atan2 function, those negatives need 360 deg added. So this is what I did (worked on theta earlier in code). But it wont work this time for phi(i,j): if phi(i,j)<0; phi(i,j)=phi(i,j)+360 end |
| Feb23-12, 04:09 AM | #3 |
|
|
the "error" your having might have simply been that you had variables in your work space from previous runs and playing in the command line. When you restart, you wipe your work space.
Try putting 'clear all' at the very beginning of your code, which will mimic having an empty workspace (like when you first start matlab). If you get the same error using 'clear all' then that's your problem. It means you're missing something in your code that you took for granted. Also, you want to nest the for loops if you want to go along the matrix like you're imagining: for i = i range for j = j range stuff phi(i,j) = blahblah stuff end end |
| Feb23-12, 05:01 PM | #4 |
|
|
Matrix help in MatLab, Not the simple matrix!! I have searched, found nothing!And also, why am I getting negative angles for phi when I said If phi(i,j)<0 phi(i,j)=phi(i,j)+360 end I can say else phi(i,j)=phi(i,j)+360 but then it just adds 360 to everything. I just need to add 360 to phi only if phi is negative. |
| New Reply |
| Thread Tools | |
Similar Threads for: Matrix help in MatLab, Not the simple matrix!! I have searched, found nothing!
|
||||
| Thread | Forum | Replies | ||
| MatLab Matrix Help | Math & Science Software | 0 | ||
| matrix in matlab | Calculus & Beyond Homework | 0 | ||
| real matrix -- eigenvector matrix R -- diagonal eigenvalue matrix L | Programming & Comp Sci | 0 | ||
| Simple MATLAB- how to find indices of max element in matrix? | Math & Science Software | 1 | ||
| Simple matrix division in Matlab | Programming & Comp Sci | 2 | ||