| | |
Integration
![]() |
I didn't understand everything...
You said,the function made by you...
Can you send some code?Too less information about your function....
You said,the function made by you...
Can you send some code?Too less information about your function....
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
There are two functions, one is for 'reading' input, and second one is for calculation. Here is code:
Delphi Syntax (Toggle Plain Text)
function RightStr(const AStr: String; Len: Integer): String; begin end; function LeftStr(const AText: string; const ACount: Integer): string; begin end; function izraz (s1: string): string; var s2 : string; t,s: array[1..30] of char; j: integer; factor,potency,posx,pos_pot: integer; polinom: array[0..10] of integer; begin repeat posx := pos('x',s2); //find x if posx > 1 then // if we find x, then read characters before x begin j:=1; repeat t[j] := s2[j]; j:=j+1; until ( s2[j] = 'x' ) ; factor := strtoint(t); end else // if x is on the first place, then factor is 1 begin if posx = 1 then factor := 1 else begin // t := niz1; s2 := ''; factor := strtoint(t); end; end; if posx >= 1 then // if x is found, search ^ begin pos_pot := pos('^',s2); if pos_pot > 1 then begin s2 := rightstr(s2,length(s2)-pos_pot); j:=1; repeat s[j] := s2[j]; j:=j+1; until ( s2[j] = '+' ) or ( s2[j] = '-' ) or ( j>length(s2) ) ; potency := strtoint(s); s2 := rightstr(s2,length(s2)-j+1); end else begin potency := 1; s2 := rightstr(s2,length(s2)-posx); end; end else potency := 0; polinom[potency] := factor; until s2 = ''; end; function integral(input: string): extended; var p,i, t2 : integer; niz1: string; l: integer; lower_limit, upper_limit: string[2]; begin delete(input,1,9); delete(input,length(input),1); p:=pos(',',input); niz1:=copy(input,1,p-1); izraz(niz1); l:=length(input); t2:=l-2; begin if input[l-3]='-' then upper_limit:=copy(input,length(input[i-3]),2); if input[i-6]='-' then lower_limit:=copy(input,length(input[i-6]),2) else lower_limit:=inttostr(l-5); if input[l-3]<>'-' then upper_limit:=inttostr(l-2); if input[l-5]='-' then lower_limit:=copy(input,length(input[i-5]),2) else lower_limit:=inttostr(l-4); end; end;
I want to understand but... my efforts wasn't success 
create a console apps and write your function there
like
Write(Integral('yourstring'));
ReadLn;{to stop the window to see the results}
press F7 to trace into the program step by step to see every commands one by one....

DELPHI Syntax (Toggle Plain Text)
function integral(input: string): extended;//WAITS STRING ,BACK EXTENDED var p,//STORES THE ',' POSITION IN THE *INPUT* STRING i, t2 : integer; niz1: string; l: integer; lower_limit, upper_limit: string[2]; begin { procedure Delete(var S: String; Index: Integer; Count:Integer); Delete deletes Count characters from S starting at the Indexth position. If Index is larger than the length of S, no characters are deleted. If Count specifies more characters than remain starting at the Indexth position, the remainder of the string is deleted. } delete(input,1,9);//DELETE(INPUT,from 1ST,9 CHARS) delete(input,length(input),1);//DELETE(INPUT,length of input,1 char) {AFTER THE TWO DELETE PROCEDURE THE *INPUT*'S VALUE IS EMPTY!!!!!} p:=pos(',',input);//HOW CAN IT FIND IN A EMPTY STRING???? { SO WHEN I TRY TO USE YOUR FUNCTION THIS IS NOT WORKING AT ALL,AND WHERE IS THE BACK VALUE Integral:=?????? this is important part of a function.... What do you want? Integrate a function to another? We need 'back value' to integrate them... }
like
Write(Integral('yourstring'));
ReadLn;{to stop the window to see the results}
press F7 to trace into the program step by step to see every commands one by one....
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
the program should know how to solve definite integral(just like we do in math). Here is link to some theory about it: http://myhandbook.info/form_integ.html
http://aleph0.clarku.edu/~djoyce/ma121/rules.pdf
http://aleph0.clarku.edu/~djoyce/ma121/rules.pdf
Kid if you're not already doing so, then use the trapezium rule.
Your program should take four arguments.
1) The function f(x)
2) The lower limit
3) The upper limit
4) The number of trapeziums to split it into
5) The height of the trapeziums
- Unless you're intend on creating somekinda generic polynomial class for trivial functions.
Your program should take four arguments.
1) The function f(x)
2) The lower limit
3) The upper limit
4) The number of trapeziums to split it into
5) The height of the trapeziums
- Unless you're intend on creating somekinda generic polynomial class for trivial functions.
Last edited by iamthwee; Jul 20th, 2009 at 6:44 am.
*Voted best profile in the world*
iamthwee, I have been doing with integrals a lot, I still am (I'm a mathematician)
I know all the rules of integration, but I don't know how to write a program which will solve integrals. As you see in my code, I split polynom and copy it into array where all numbers from polynom are saved. I also save lower and upper limit. Now, despite knowing rules for integration, I don't know how to calculate the whole thing in Delphi.
I know all the rules of integration, but I don't know how to write a program which will solve integrals. As you see in my code, I split polynom and copy it into array where all numbers from polynom are saved. I also save lower and upper limit. Now, despite knowing rules for integration, I don't know how to calculate the whole thing in Delphi. •
•
Join Date: Jun 2009
Posts: 5
Reputation:
Solved Threads: 0
Hi Anna,
I'm pretty sure that I can help you with this, but of course I need to make sure I understand how to arrive at the correct answer to be of any help at all.
It has been about 4 years since the last time I was exposed to integrals. I am trying to solve your equation in order to understand what needs to be done programmatically. I am not finding your solution of 12. I'll walk you through my calculations. Show me where I'm wrong, and once I understand I can help.
So, we have the antiderivative of x^2+3 is (x^3)/3 + 3x
Solve for 2 = 2 2/3 + 6 = 8 2/3
Solve for -1 = -1/3 -3 = -3 1/3
Solution = 8 2/3 - -(3 1/3) = 12
OK so... I realized after typing the above that I missed the double-negative in the middle, I originally came out with 5 1/3, but I see my 'simple' mistake. I'm going to post this anyway for anyone else that may have been confused by the math involved.
I've got your code compiling, but I get errors all over the place when it tries to do the parsing you've programmed. I will continue looking at this and see if I can figure something out for you.
I'm pretty sure that I can help you with this, but of course I need to make sure I understand how to arrive at the correct answer to be of any help at all.
It has been about 4 years since the last time I was exposed to integrals. I am trying to solve your equation in order to understand what needs to be done programmatically. I am not finding your solution of 12. I'll walk you through my calculations. Show me where I'm wrong, and once I understand I can help.
So, we have
•
•
•
•
integrate(x^2+3,-1,2) solution: 12
Solve for 2 = 2 2/3 + 6 = 8 2/3
Solve for -1 = -1/3 -3 = -3 1/3
Solution = 8 2/3 - -(3 1/3) = 12
OK so... I realized after typing the above that I missed the double-negative in the middle, I originally came out with 5 1/3, but I see my 'simple' mistake. I'm going to post this anyway for anyone else that may have been confused by the math involved.
I've got your code compiling, but I get errors all over the place when it tries to do the parsing you've programmed. I will continue looking at this and see if I can figure something out for you.
Yes well that is about as trivial as integration gets. The problem is when you want to consider trig functions etc.
I'm not sure exactly what you wish to do.
Do you want to enter ANY trivial expression at the command line? If that is the case then you have lots of issues.
1) You will have to write a parser (choices include RPN stacks, or building expression trees) to store your expression.
2) Once having stored that expression you can then find the integral by either using numerical methods such as the trapezium rule/Simpson's rule. This is the most easiest solution as you can apply this to more complicated functions with trigonometric values as long as you have lower and upper bound values.
The other solution is to now write your own univariate polynomial class to integrate your function. On top of that you will have to write ANOTHER parser to separate each term into its coefficient and exponent.
The easiest solution to this problem is to hard code the function in the program and then to evaluate an approximate solution using the trapezium rule. - after all integration is simply finding the area under the graph for that function given definite lower and upper bounds.
There's your food for thought.
I'm not sure exactly what you wish to do.
Do you want to enter ANY trivial expression at the command line? If that is the case then you have lots of issues.
1) You will have to write a parser (choices include RPN stacks, or building expression trees) to store your expression.
2) Once having stored that expression you can then find the integral by either using numerical methods such as the trapezium rule/Simpson's rule. This is the most easiest solution as you can apply this to more complicated functions with trigonometric values as long as you have lower and upper bound values.
The other solution is to now write your own univariate polynomial class to integrate your function. On top of that you will have to write ANOTHER parser to separate each term into its coefficient and exponent.
The easiest solution to this problem is to hard code the function in the program and then to evaluate an approximate solution using the trapezium rule. - after all integration is simply finding the area under the graph for that function given definite lower and upper bounds.
There's your food for thought.
Last edited by iamthwee; Jul 21st, 2009 at 7:02 am.
*Voted best profile in the world*
![]() |
Similar Threads
- HSBC Payment integration (PHP)
- QA Integration Analyst (Tech / IT Consultant Job Offers)
- Maths - Integration in Java (Java)
- phpBB to php-nuke integration help (PHP)
- Custom pages with vBulletin integration (Growing an Online Community)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Working with threads
- Next Thread: Please express the meaning of the following answer.
| Thread Tools | Search this Thread |






