Trying to Loop through different values of two matrixes simultaneously

조회 수: 5 (최근 30일)
Michael Costa
Michael Costa 2020년 10월 16일
답변: Matt J 2020년 10월 16일
I have a program that calculates the grain boundary energy (single output) given inputs of two 3 by 3 matrices, let's call them matrix A and matrix B. These matrices tell the program the relative orientation of two grains in the metal. I need to write another program that optimizes the grain boundary energy by finding the orientation (two matrices) that minimizes the energy. My thought of how to do this is to loop through "all" (starting off i would want each matrix element to start at zero, step by 0.01, and go to say, 10) the values of each matrix element. After all the energies (again, single outputs corresponding to each iteration of inputs A and B) are calculated, I would have MATLAB find the minimum values, say the lowest 50% of energies. So far I can't figure out how to test every combination of the elements of matrix A with every combination of the elements of matrix B. Any help or even ideas on this would be much appreciated.
Thanks
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2020년 10월 16일
hello
this is a first level description of the problem, but we need to understand from a mathematical perspective how the elements of A and B are defined , not only the range but how each element is related to the others (random distribution ? )
what are the operation(s) you have to do on the A and B matrixes to compute your energie(s) ?
a kind of pseudo code would be helpful

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2020년 10월 16일
You can form all combinations of two matrices using ndgrid,
A=rand(3), B=rand(3)
A = 3×3
0.2535 0.4016 0.2631 0.3204 0.5844 0.9297 0.6106 0.9268 0.6711
B = 3×3
0.7170 0.9237 0.3843 0.4447 0.0765 0.5473 0.0286 0.6168 0.3079
[AA,BB]=ndgrid(A,B)
AA = 9×9
0.2535 0.2535 0.2535 0.2535 0.2535 0.2535 0.2535 0.2535 0.2535 0.3204 0.3204 0.3204 0.3204 0.3204 0.3204 0.3204 0.3204 0.3204 0.6106 0.6106 0.6106 0.6106 0.6106 0.6106 0.6106 0.6106 0.6106 0.4016 0.4016 0.4016 0.4016 0.4016 0.4016 0.4016 0.4016 0.4016 0.5844 0.5844 0.5844 0.5844 0.5844 0.5844 0.5844 0.5844 0.5844 0.9268 0.9268 0.9268 0.9268 0.9268 0.9268 0.9268 0.9268 0.9268 0.2631 0.2631 0.2631 0.2631 0.2631 0.2631 0.2631 0.2631 0.2631 0.9297 0.9297 0.9297 0.9297 0.9297 0.9297 0.9297 0.9297 0.9297 0.6711 0.6711 0.6711 0.6711 0.6711 0.6711 0.6711 0.6711 0.6711
BB = 9×9
0.7170 0.4447 0.0286 0.9237 0.0765 0.6168 0.3843 0.5473 0.3079 0.7170 0.4447 0.0286 0.9237 0.0765 0.6168 0.3843 0.5473 0.3079 0.7170 0.4447 0.0286 0.9237 0.0765 0.6168 0.3843 0.5473 0.3079 0.7170 0.4447 0.0286 0.9237 0.0765 0.6168 0.3843 0.5473 0.3079 0.7170 0.4447 0.0286 0.9237 0.0765 0.6168 0.3843 0.5473 0.3079 0.7170 0.4447 0.0286 0.9237 0.0765 0.6168 0.3843 0.5473 0.3079 0.7170 0.4447 0.0286 0.9237 0.0765 0.6168 0.3843 0.5473 0.3079 0.7170 0.4447 0.0286 0.9237 0.0765 0.6168 0.3843 0.5473 0.3079 0.7170 0.4447 0.0286 0.9237 0.0765 0.6168 0.3843 0.5473 0.3079

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by