How to differentiate condition in if statements

2 views (last 30 days)
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 Comments

Sign in to comment.

Answers (0)

Categories

Find more on Variables in Help Center and File Exchange

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!