Hello,
I am relatively new to programing. I have written the following function to be optimized by another MATLAB function that I found online:
function z = PSO_inv(x)
DM=dlmread('DM.dat','\t',1,0);
mp=length(DM);
for i=1:mp
DC(i,:)=forward_p(x);
end
t=0;
for k=1:4
for i=1:mp
t = t + (((DM(i,k)-DC(i,k))/DM(i,k))^2);
end
end
z=100*sqrt(t/4);
end
I have two matrices DM and DC, both are 206x4, and would like to minimize the difference row by row, but I think my code now tries to do the optimization for the whole dataset at once.
Thank you, any help is appreciated!

댓글 수: 2

Jan
Jan 2018년 2월 20일
What is "forward_p"? What is "x" and the contents of "DM"? What exactly does "minimize the difference row by row" mean?
Lucas
Lucas 2018년 2월 20일
편집: Lucas 2018년 2월 20일
It is kind of an inverse problem.
So DM contains 4 measured parameters at 206 different locations, that's why it is 206x4. Then forward_p calculates theoretical values of these "measurements" with some defined response functions using "x" that contains 3 different parameters, so it is a vector of 1x3. The aim would be to find the values of x that minimizes the difference between the measured (DM) and theoretical (DC) data for all 206 locations separately.
So first, it should compare the first row of DM with the first row of DC and then modify the values of x so that the difference between DM and DC is minimal, here set the values of x, then continue with the second row and etc.
Btw, if I delete the for loop and just manually set DM to contain the first raw of the data set, for example [1 3 7 9] and I calculate DC which then will also contain only 4 values and redefine the way I want to measure their difference accordingly the program seems to work just fine.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Parallel Computing Toolbox에 대해 자세히 알아보기

질문:

2018년 2월 20일

편집:

2018년 2월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by