Click here to Skip to main content
15,400,388 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I need help in coding (using Microsoft Visual studio C++) for Adams Moulton method for variable step size. Can any one help me to find my mistake 

What I have tried:

I am stuck in finding the maximum error.

void FNMAXE(double A, double B, double TEMP[DIM][DIM])
//double A,B,TEMP[DIM][DIM];
	int i, j;
	double TMP;//Fex[10][DIM];
			   //void SOLN();

	for (i = 1; i <= PO; i++)
		SOLN(i + 2, Fex);
		for (j = 1; j <= EQN; j++)
			TMP = A + B * fabs(Fex[i + 2][j]);
			TEMP[i][j] = fabs(Y[t][i + 2][j] - Fex[i + 2][j]) / TMP;

Here is the command for finding the Max Error

I am getting the maximum error for this problem

K[p][1] = Y[t][p][2];
K[p][2] = 2. * Y[t][p][2] - Y[t][p][1];


MAX ERROR = 7.91476569e-01
AVERAGE ERROR = 2.16145282e-01
XEND = 1.89352261e+01

and to find the max error, the formula is |(ynew-yold)/(A+B*y(old))|.

Am i giving the correct command for finding the Max error
Updated 22-Jun-22 23:31pm
Rick York 22-Jun-22 23:44pm
We can't find a mistake in code we can't see.
Dave Kreskowiak 22-Jun-22 23:45pm
You're not going to get an answer to this unless you add your code to your question. Nobody can help you with your code unless you show it.
Patrice T 23-Jun-22 0:12am
you have a secret error in your secret code.
CPallini 23-Jun-22 2:02am
I do have a fix for your code. However it is confidential and I cannot share it here.
Hira Soomro 23-Jun-22 2:10am
Same here Sir. Can you just give me a hint on how to tackle that maximum error part? I somehow managed to get the successful number of steps. only stuck on the Maximum Error part after LTE.
Richard Deeming 23-Jun-22 4:46am
The error is on line 42 - you have a + instead of a - between frob and fubar.

Seriously, read the comments again: nobody can help you fix an error in code if we can't see the code.

As it stands, your question is simply: "Here's my homework assignment; do it for me."

Click the green "Improve question" link and update your question to include the relevant parts of your code, the input values you're using, the expected output, the actual output, and a clear and complete description of what you have tried and where you are stuck.

Without that, your question will simply be ignored and/or closed.
CPallini 23-Jun-22 5:43am
Still, is not clear was going on.
Could you please detail what your code should do, what is the input and what is the expected output?
Hira Soomro 23-Jun-22 5:48am
as adams moulton method is an implict linear multi step method so i want to write a code for that can solve first order ODEs specifically for variable step sizes as r=1,2 and 1/2. So i want my output as less total of steps with good maximum error. i managed to get the less total number of steps but i cannot find where i am making mistake for finding the maximum error. As that's why i just shared the FNMAXE part here. As it is still ongoing research so I cannot share the complete code. I hope as researcher you will understand.
Richard MacCutchan 23-Jun-22 5:21am
Please remove all the comments which are not relevant to the problem, and explain exactly what is wrong.

1 solution

Can any one help me to find my mistake
Actually code is bit confidential as it belongs to my research work.

We cannot help you fix a problem with your code if we cannot see the code you have written: that would be like you asking the garage to fix your car engine, but not letting them know what make, model, or year it is, and refusing to bring it to the garage!

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900