I am getting NaN as answer in the code, can please give me some advice

I have attached the code in a comment , if you guys have any advice thank you

1 Comment

yes I solved by A=zeros(239,239) and B=zeros(239,1) ,,, I am getting all the temperatures for the nodes, yet when I tried to plot it in using the code attached it tells me that index exceeds matrix dimension , any advice ? and thank you very much

Sign in to comment.

 Accepted Answer

What is your line
T_new=T(1:182,T_1,183:207,T_1,200:216,T_2,217:233,T_2)
intended to mean?
I suspect you want
T_new=T(1:182, [T_1,183:207,T_1,200:216,T_2,217:233,T_2])
Note: your T_1 and T_2 are empty. You assigned them on the line above with
T_1=t_i*ones(8:1)
T_2=t_i*ones(16:1)
which should probably be
T_1=t_i*ones(1, 8);
T_2=t_i*ones(1, 16);

8 Comments

Thank you for your help but still is not running the code, I keep getting the same error. Index exceeds matrix Dimensions. I added a pic of what I am trying to do. I have completed the nodes of the object and want to add nodes for the empty space which are T_1 and T_2 ... which will have the fluid temperature.
Just want to have a big matrix of 33x9 so I can plot the heat transfer , thank you very much for your advice
I suggest that you do not try to put it together that way. Instead, allocate a 33 x 9 array and store the other sub-arrays into the appropriate sub-positions.
can you please give me an example of how , I am just confused .. thank you very much
Sorry, I just do not understand your notation. Are you trying to create a 33 x 9 matrix, or a 33 x 217 matrix, or a 33 x 233 matrix?
The line after you assign to T_new has
T_p =reshape(T_new,33,8)';
which implies that T_new should be something compatible with 33 x 8?
The bottom line in your diagram ends at 165, but directly above there is 157? Then across from there is 207 but directly above the 207 is 199? Right of there is 233, but directly above 233 is 217 ??
I do not know. Perhaps what you want is
T_1=t_i*ones(1, 8);
T_2=t_i*ones(1, 24); %NOTE SIZE CHANGE
T_new = [T(1, 1:182), T_1, T(1,183:207), T_1, T(1, 208:216), T_2, T(1, 217:233) ,T_2];
that would be 297 items, and that could be reshaped to 33 by 9
To get this to work the sum of the sizes of T_1 and T_2 must be 32, but the distribution does not need to be 8 and 24.
what I am trying to do is a 33 by 9 matrix, just the object nodes and add nodes (for the temperature of the fluid surrounding the object), the object is between the lines and I am trying to add those "air " nodes to the 249 that I have to have a total of 297 ( 33 by 9), so after 182 add 8, after 207 add 8, after 216 add 16 and after 233 add 16. So It is a nice rectangle "object" so I can do further calculations and it will be easier. Thank you very much
Ah, finally I understand! The code you need is
T_new = zeros(33, 9);
-> at this spot transfer in a bunch of values from T <-
%then
T_new(26:end, 6) = T_1;
T_new(26:end, 7) = T_1;
T_new(18:end, 8) = T_2;
T_new(18:end, 9) = T_2;
You counted down from 133 to the corner that you labeled 157, and you started the next column at 158, counted down from there to the edge at 182, and started the next column at 183, counted down from there to the corner you labeled 199, started the next column at 200, counted down from there to 216, started the next column at 217, counted down from there to 233. But that is wrong!
When you got to the corner at 157 you also counted down from there to the bottom, labeling those up to 165, so the node you would label as 158 would be both the one at the top of column 6 (that you specifically labeled) and the one directly below 157. Likewise everything up to 165 is duplicated. And when you got to 199 and started the next column at 200, you also kept counting down the line to 207, so the node numbers 200 to 207 are also duplicated!
Notice that you are adding 8+8+16+16 = 48 entries within the 33 x 9 = 297 entries, so the part that is to come from T must have 297 - 48 = 249 entries, not 233. The extra 249 - 233 = 16 that you missed out are the 16 locations that you accidentally re-used the labels for.
Because of this, I could not reliably decide what part of T you want transferred to where in the new matrix.
yes I just saw my mistake thank you very much , I am correcting the code , so edge 182 should be 190. edge 207 should be 215, edge 199 should be 207 , edge 216 should be 232 and edge 233 is 249. Thank you very much for your help
Thank you , now T_new has the nodes for the fluid temperature and how should I add the previous matrix T so is all a matrix (33 by 9) with T and the four T_new?

Sign in to comment.

More Answers (1)

inv(A) generates a matrix of inf's, B contains 0's, inf*0 = NaN

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!