Fitting

Hi every one.
I have two text file. I wanna to fit two curve on this data points and then i wanna to find the cross point of two curves.
can you help me?
Bing or google for 'curve fitting freeware' and pick what fits best for you. To get an impression about the vast field of eventualities possible by your sparsly precise "I wanna to fit two curve on this data points" see:
https://www.bing.com/images/search?q=Curve+fitting&qpvt=Curve+fitting&FORM=IGRE
Hello jasper hall,

There are several people here who can help, but without posting any code of what you have done it is unlikely you will find anyone willing to do the work for you.

First you have to help yourself. You say you have two files to read, so post the contents, or a fair sample, so that everyone can use the same information and see what has to be read.

Then post what code you have and point out any problems that you have.

First I would work on opening the files and reading from the files. Then you can decide if you want to store this information in something for later use or just read and process the file.

This is just one way you can deal with a file stream. It may not be the best, but I found it useful when learning to deal with files.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <iomanip>
#include <string>
#include <limits>
#include <chrono>
#include <thread>

#include <fstream>

// --- Add any header files you create.

// <--- Constant global variables.

// <--- Prototypes.

int main()
{
	// <--- Define variables. Just one option.

	// <--- Your code here.
	const std::string inFileName{ "" }; // <--- Put file name here.

	std::ifstream inFile(inFileName);

	if (!inFile)
	{
		std::cout << "\n File " << std::quoted(inFileName) << " did not open" << std::endl;
		std::this_thread::sleep_for(std::chrono::seconds(3));  // <--- Needs header files "chrono" and "thread".
		return 1;  //exit(1);  // If not in "main".
	}

	// <--- Code to read the files.

	// <--- Keeps console window open. These lines may not be needed.
	// <--- Keeps console window open when running in debug mode on Visual Studio.
	// The next line may not be needed. If you have to press enter to see the prompt it is not needed.
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
	std::cout << "\n\n Press Enter to continue: ";
	std::cin.get();

	return 0;
}

You can add something to "inFileName" and "inFile" to distinguish which file it is working with.

The reason for leaving the program in the if block is if there is a problem it needs to be addressed before you continue with the program.

I would work on this part first because until you can read from the files the rest of the program is irrelevant until you have something to work with.

In the code lines 34 - 39 are optional. If you do not need them comment them or delete them.

Hope that helps,

Andy
dear @Handy Andy
This two text file are the result of my main code. I have not any idea for fitting.I am looking for a way that i can fit a function on data points. But i will try to write something again.
@Handy Andy and @MikeStgt thanks for your help.
@jasper hall,

Please give a (short) example of your data files.

If the data points have the same X coordinates then it should be relatively straightforward: set up an array with the difference between Y values first and look for the zero-crossings.

If the data points don't have the same X coordinates then you will have to interpolate onto the same coordinates first.

We don't know yet whether you are talking about "best-fit" curves of particular parametric shapes, or spline curves, or simply polylines through successive data points. You haven't given enough information.
This two text file are the result of my main code

Sorry, but if you have computed values from a main code of your own you do have a function or procedure or formula or way to calculate, don't you? Fit a function to your computed figures should result to something very close to the formula in your main code.

Typically you fit functions to measured values, so to interpolate as a makeshift where you did not measure.
Topic archived. No new replies allowed.