Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

For the code below how would I make it ALWAYS select and set the upper left corner to be 1 always no matter what the n value is (10, 1000, 1000000)?

조회 수: 1 (최근 30일)
n=10; % number of nodes in the x-direction
meshsize = n*n/2;
nodes = 1:meshsize;
nodetype = zeros(n/2, n);
delx = 2/n;
[X,Y] = meshgrid(delx:delx:2,delx:delx:1);
for i = 1:length(nodes)
if X(i) == .2 && Y(i) == .2 %DOESNT SCALE
nodetype(i) = 1;
%FOR TOP LEFT CORNER
end
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 10월 2일
Still, Question is not clear for me, can you elaborate more?
Be Specific?
Josh Glenn
Josh Glenn 2018년 10월 2일
So, my full code is posted below...It is a project to select and set each node in a heat transfer system and certain node points have different conditions and equations to use. I'm currently in the stage where I'm assigning each node type so that I can later evaluate each one based on its conditions. I'm currently stuck with how to set the corner nodes while allowing the n value to scale.
Does this help you to better understand the question?
%%Clear, clc, close, format
clear
clc
close all
format short
%%knowns
n=10; % number of nodes in the x-direction
%Create Mesh based on n
meshsize = n*n/2;
nodes = 1:meshsize;
nodetype = zeros(n/2, n);
delx = 2/n;
[X,Y] = meshgrid(delx/2:delx:2,delx/2:delx:1);
%Problem Givens
T1 = 28; %C
T2 = 50; %C
T3 = @(y) 10 + 14*y; %C
T_inf = 32; %C
h = 28; %W/m^2*K
k = 12; %W/m*K
q_dot = 47000; %W/m^3
%%Node Stuff
for i = 1:length(nodes)
if X(i) == .1 && Y(i) == .1 %DOESNT SCALE
nodetype(i) = 1;
%FOR TOP LEFT CORNER
elseif X(i) == 1.9 && Y(i) == .1 %DOESNT SCALE OR WORK
nodetype(i) = 2;
%FOR TOP RIGHT CORNER
elseif X(i) == .1 && Y(i) == .9 %DOESNT SCALE
nodetype(i) = 3;
%FOR BOTTOM LEFT CORNER
elseif X(i) == 1.9 && Y(i) == .9 %DOESNT SCALE OR WORK
nodetype(i) = 4;
%FOR BOTTOM RIGHT CORNER
elseif X(i) > .1 && X(i) < 1.9 && Y(i) == .1 %DOESNT SCALE
nodetype(i) = 5;
%FOR TOP EDGE
elseif X(i) == .1 && Y(i) > .1 && Y(i) < .9 %DOESNT SCALE
nodetype(i) = 6;
%FOR LEFT EDGE
elseif X(i) == 1.9 && Y(i) >.1 && Y(i) < .9
nodetype(i) = 7;
%FOR RIGHT EDGE
% elseif
% nodetype(i) = 8;
% %FOR BOTTOM LEFT EDGE
% elseif
% nodetype(i) = 9;
% %FOR BOTTOM RIGHT EDGE
% elseif
% nodetype(i) = 10;
% %FOR BOTTOM LEFT INNER CORNER
% elseif
% nodetype(i) = 11;
% %FOR BOTTOM RIGHT INNER CORNER
% elseif
% nodetype(i) = 12;
% %FOR BOTTOM LEFT INNER SIDE
% elseif
% nodetype(i) = 13;
% %FOR BOTTOM RIGHT INNER SIDE
% elseif
% nodetype(i) = 14;
% %FOR BOTTOM CENTER EDGE
% elseif
% nodetype(i) = 15;
% %FOR FULL GENERATION
% elseif
% nodetype(i) = 16;
% %FOR HALF GENERATION
% elseif
% nodetype(i) = 0;
% %FOR NOTHING THERE (EMPTY)
else
nodetype(i) = 17;
%Regular Nodes
end
end

답변 (1개)

Dennis
Dennis 2018년 10월 2일
I am only guessing, but i assume you want nodetype(1,1) to be 1? The easiest way of doing this would be:
nodetype(1,1)=1;
actually this does the same:
nodetype(1)=1;
Now your loop does not set the top left corner to 1, but rather checks for 0.2 values. However depending on your n it is very possible that there are none in your matrix. This is obvious for n=98, but it is also true for n=100, although the variable inspector might tell you something different on the first look.
The reason for this is that not every floating point number can be represented exact in binary form. For more information on this topic please look here.
  댓글 수: 1
Stephen23
Stephen23 2018년 10월 2일
편집: Stephen23 2018년 10월 2일
"... not every floating point number can be represented exact in binary form"
By definition, all binary floating point numbers are stored in a binary form, which exactly represents that floating point number... did you actually mean something like "not all decimal fractions are representable using (finite) binary floating point numbers"?

이 질문은 마감되었습니다.

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by