How can I calculate the index of error between two curves?
I want to make a program to calculate index of error between two Curves (one measured and the other calculed) ym=f(xm) et yc=f(xc). This index is known as: gamma=minimum{((xm^2-xc^2)^2/4)+(ym^2-yc^2)^2/4)}. I have data with 4 columns xm,ym,xc and yc("file.dat")with 163 lignes. Can someone help me?
looks like you read the file variables, compute the equation you gave, and take the smallest result from those computations.
you appear to be opening the same file twice in this code. do you have 2 data files?
while !eof does not work like you want it to. do while file>> variables instead, or as you did the first time, read your know number of lines is OK here.
1/2 power is sqrt()
you only need 1 min, not 163 of them. you can do it that way, but you don't need it. just set min = first result, and after that, if new result < min update min.
I think you are close, without going over in much more detail; I suspect the filename is your problem if its not working right..
integer powers with pow are sluggish (by a full order of magnitude on my machine). If you had to do a lot of them (billions), you would want to use x*x instead of pow(x,2).
Thanks for your feedback,
I have only one file. I have used two loops because I want to calculate this index for each point (xm, ym), the first loop is to fix the point (xm, ym) and the second loop to change xc and yc until the minimum gamma value is reached for this measured point , The index will be recalculated for each measured point because of the first loop (minimum for each measured point=>163 min).
Are you trying to do a kind of double loop through the same file? If so, it's probably better to read it into a vector and loop through that.
Also, it looks like your formula is coded wrong. You need to square the variables before you subtract them (and after, as you are doing). You should make the calculation a function.
If you could describe your problem more precisely it would be easier.
As I understand your program, you first calculate the half distance between measured points and corresponding calculatet points. Then, in an inner loop you scan through the complete file again and look for an other calculated point that is closer to the current measured point, right? Alas, for the second measured poin you did not "rewind" the reading position within the file, and results for point 2 to n are wrong. Right?
I suggest -- 163 rows with four colums are close to nothing -- read the file to an array or vector or what offers access to single values by index and do your computing with it. "Rewinding" will then be just to restart the inner loop from zero.
I apologize to everyone. I did not explain the problem well because of my weakness in English.
for dutch: the formula in the script is correct I've been wrong in the problem description. This formula is called "gamma index"if you've heard anything around it before.
for MikeStgt: yes, you are right. As for your suggestion, I have problems with arrays because I have not worked on c++ for a long time. Due to lack of time I do not have time to review.
I would appreciate any help provided to resolve this problem
Could you give us what's written in file.dat ? If the file contains a duplicate of the numbers then you don't need to reset the position, but it all depends on the file.
Also, use code tags. You can edit your post, highlight your code, and then press on the <> on the side.
What's the output of your code? Is it what you want? And use the formula I showed you. Put it where you need it, probably at the very end.
This part of the file.data with the script I sent earlier results are not good. But when I tried the code sent by dutch, the results looked good
Thanks to all.