Mathematical modeling record (3)

xiaoxiao2021-03-06  80

1. Function name: Crtpower (a)

Role: Calculate vector rights in the matrix

Advantages: Directly converted to vector rights in the matrix directly from raw data

Source code:

Function Rstpower = CRTPOWER (a)% ***************************************************** ***************% this is help information about power () function.% Find The min number in the massage.% Verison: 1.2.0 finish date: 30/08/2004 % USAGE:% POWER (a)% a is matrix.% Return a rstpower.% ******************************************* *****************************

IF Nargout> 1 Error ('Too Many Output Arguments!); Else IF (Nargin <1 | Nargin> = 2) Error (' Too Many Input Arguments! '); Else Sumcols = Length (A (1, :)) ;% Get the cols of the matrix. If sumcols> = 3 Sumrows = Length (a (:, 1));% get the rows of the matrix. Rstpower = Zeros (Sumrows); for col = 2: Sumcols-1 Parcol = a (:, color); befcol = a (:, col-1); AFTCOL = a (:, col 1); for rowcount = 1: sumrows; for tmprow = 1: sumrows; if rowcount == TMPROW RSTPOWER (RowCount, TmpRow) = 0; Else if Parcol (RowCount) -befcol (TMPROW)> = 0 TMPM = Parcol (Rowcount) -befcol (TMPROW); if Aftcol (Rowcount) -parcol (TMPROW)> = 0; TMPN = Aftcol (Rowcount) -parcol (TMPROW); Else Tmpn = Aftcol (Rowcount) -parcol (TMPR OW); END; RstPower (RSTPower (RowsTPower (RowCount, TmpRow) ABS (TMPM) ABS (TMPN) - (COL-2) * ABS (TMPM); Else TMPM = (Sumcols-Col 1) * (Parcol (Rowcount) -befcol (TMPROW)); if atcol (rowcount) -parcol (tmprow)> = 0; TMPN = AFTCOL (ROWCOUNT) -Parcol (TMPROW); Rstpower (RowCount, Tmprow) = Rstpower (Rowcount, TMPROW) ABS (TMPM TMPN) - (COL-2) * ABS (TMPM);

Else Tmpn = AftCol (RowCount) -parcol (TMPROW); Rstpower (RowCount, Tmprow) = Rstpower (RowCount, TmpRow) ABS (TMPM) ABS (TMPN) - (COL-2) * ABS (TMPM); End; end;% end if end;% END TMPROW for end;% END ROWCOUNT for end;% end col for else error ('Length of the Martrix Is Too Short! The Minium Number IS 3!'); END;% end If SUMCOLS> = 3 End;% endiff (Nargin <1 | Nargin> = 2) end; 2. Function Name: Findminparam (A, ICOUNT, DIFF)

Role: Find the minimum number of ICOUNT specified in the matrix. Find in a peer (DIFF = 0, default), minimum value in different lines (DIFF = 1)

Advantages: Direct data directly, you can find the rows and columns of smaller elements in the matrix.

Source code:

Function RST = FINDMINPARAM (A, ICOUNT, DIFF)% ******************************************************* *****************% This is help information about findminparam () function.% Find the min number in defferent rows and color the matrix.% Verison: 1.1.2 Finish Date: 28/08/2004% USAGE:% Findminparam (A, ICOUNT, DIFF)% a is Matrix.% ICount Is Counter.% Diff is the parame to find the mininum in diffreent rot.% ****** *********************************************************** ***

IF Nargout> 1 Error ('Too Many Output Arguments!'); Else IF (Nargin == 0 | Nargin> 3) Error ('Too Many Input Arguments!'); Else Cols = Length (A (1, :)) Rows = Length (a (:, 1)); if Nargin == 1 iCount = ROWS * COLS; DIFF = 0; End; if Nargin == 2 | Nargin == 3 if Icount> Rows * cols Error ('THE Search number is too big! '); ICOUNT = ROWS * COLS; Elseif iCount <1 Error (' the mininum is 1 '); ICOUNT = 1; else iCount = ICOUNT; END; if Nargin == 3 if Diff == 1 DIFF = 1; ELSE DIFF = 0; END; ELSE DIFF = 0; end; end; rst = Zeros (ICOUNT, 3); for count = 1: ICOUNT SUCC = 0; for rowcount = 1: rows; for color = 1 : Cols; if (min (min (a)) == a (rowcount, colcount)); TMPMIN = Min (min (a)); tmproW = rowcount; tmpcol = colcount; if Diff == 1 A (RowCount,:) = INF; A (:, colcount) = INF; Else A (Rowcount, Colcount) = INF ; END; SUCC = 1; Break; end;

End% end for if succ == 1 Break; end; end; if SUCC == 1 RST (count, 1) = tmpmin; RST (count, 2) = TmpRow; RST (count, 3) = tmpcol; end; end; DISP (RST); END; END; face problem:

1. CrtPower function also needs to continue to improve, testing it can be extended to more questions;

2. Can you add a function to the FindMinParam program and use the user to specify the data you want to find.

3. Can I expose the final result with an intuitive map?

to sum up:

This model has improved in promotion. Everyone is also better to make this experiment, it is worth mentioning. There is also a certain increase in the program.

转载请注明原文地址:https://www.9cbs.com/read-121938.html

New Post(0)