How to differentiate condition in if statements
2 ビュー (過去 30 日間)
古いコメントを表示
surendra kumar Aralapura mariyappa
2019 年 6 月 13 日
コメント済み: surendra kumar Aralapura mariyappa
2019 年 6 月 15 日
Hey all,
I know what I am asking is wrong, but I have to slove it at any cost.
I have sOme materials .1 2 3 4 5 6 7 8 9 10;
Now 1 and 2 are in series 1--2
2 and 3 are in series 2--3
3 and 4 are in series 3 --4
1 and 5 are in parallel =
8 and 5 are in series 8-5
8 and 6 are in parallel =
6 and 7 are in series 6-7
5 and 9 are in Series 5 - 9
9 and 10 are in series 9 -10
9 are 2 are in parallel =
10 and 3 are in parallel =
Now I need to build separate function file to let the slover knows which one is in parallel or series with other element.
My code is like this:
classdef Connection
enumeration
Series, Parallel
end
end
function [C] = find_Connection(i)
[Lambda, A, B, D, M, A1,M_S, M_P] = Matrix_surendra13; %% this is the input file which %contains the input arguments.
C = 0;
% M_S is a row vector which contains materials in Series . M_S = [ 1 2 3 4 5 8 6 7 9 10];
%M_P is a row vector which contains materials in parallel M_P = [ 1 5 7 9 10];
if (find(M_S == i))
C = Connection.Series;
elseif (find(M_P == i))
C = Connection.Parallel;
end
function Slover
[Lambda, A, B, D, M, A1,M_S, M_P] = Matrix_surendra13; % ignore this called function it is just an %input argument file
for i = 1:Size(A,1) % A from the input argument file square matrix always
for j = 1:size(A,2)
C1 = find_Connection(i);
C2 = find_Connection(j);
if (C1 == Connection.Series && C2 == Connection.Series)
LA = A(i,j)*B(i)*D(j)*Lambda(j);
elseif (C1 ==Connection.Parallel && C2 == Connection.Parallel)
LB = A(i,j)*Lambda(i)*Lambda(j);
end
So the problem is each material has two possiblities either Series or Parallel with others. If I use my code it doesn't work.
For an example,
i = 1; j = 1;
Material 1 is in Series with 2 and in Parallel with 5, when the solver enter the function file find_Connection(i) it will automatically take Series statement since first condition will be fulfilled. This is fine for 1 and 2. LA will be computed.
But when i = 1 and j = 5; in parallel
slover sholud take LB, but it will compute LB bcoz both i = 1 and i = 5 are there in series vector file as well as in parallel vector file, so first condtion in the find_Connection file will be fulfuilled, so solver will not check second one.
I think that I gave the proper explanation.
Kindly as for the more detail if it is not clear.
any suggestions and answers are most welcomed.
Thanks in Advance.
3 件のコメント
James Browne
2019 年 6 月 15 日
編集済み: James Browne
2019 年 6 月 15 日
I agree with that strategy, even a simple cell array could do the trick, like:
materialCombos = {...
'1' '2' 'series'
'2' '3' 'series'};
Then the following parameters are easily accesed:
material1 = materialCombos(i,1);
material2 = materialCombos(i,2);
relationship = materialCombos(i,3);
Then you just sent material1, material2 and relationship to your solver~
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!