row by row minimization

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 Commenti

Jan
Jan il 20 Feb 2018
What is "forward_p"? What is "x" and the contents of "DM"? What exactly does "minimize the difference row by row" mean?
Lucas
Lucas il 20 Feb 2018
Modificato: Lucas il 20 Feb 2018
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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Richiesto:

il 20 Feb 2018

Modificato:

il 20 Feb 2018

Community Treasure Hunt

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

Start Hunting!

Translated by