• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

translate from pseudocode into java  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello im new here,recently my lecturer held open-book-Quiz about Numerical method also its not a homework everytime we joined his classes,this time its modified false position method,the pseudocode found in my pdf which distributed by my lecturer so here the pseudocode :
'FUNCTION ModFalsePos(xl, xu, es, imax, xr, iter, ea)
iter 5 0
fl 5 f(xl)
fu 5 f(xu)
DO
xrold 5 xr
xr 5 xu 2 fu * (xl 2 xu) / (fl 2 fu)
fr 5 f(xr)
iter 5 iter 1 1
IF xr , . 0 THEN
ea 5 Abs((xr 2 xrold) / xr) * 100
END IF
test 5 fl * fr
IF test , 0 THEN
xu 5 xr
fu 5 f(xu)
iu 5 0
il 5 il 1 1
If il $ 2 THEN fl 5 fl / 2
ELSE IF test . 0 THEN
xl 5 xr
fl 5 f(xl)
il 5 0
iu 5 iu 1 1
IF iu $ 2 THEN fu 5 fu / 2
ELSE
ea 5 0
END IF
IF ea , es OR iter $ imax THEN EXIT
END DO
ModFalsePos = xr
End MODFALSEPOS'

and here my attempted translate java code :


I tried to printout  whole number in modified false position method but its just print one and also what does mean "ModFalsePos 5 xr" ?
 
Saloon Keeper
Posts: 4870
117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that pseudocode is impossible to make sense in a reasonable amount of time as. What is it supposed to do? What do the 7 parameters do?

Not so humorous aside: if a method has 7 parameters, it's probably missing a few more.
 
Master Rancher
Posts: 3677
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not pseudocode.
It's pretty much unintelligible.
Looks more like some form of assembly.
 
Marshal
Posts: 60867
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

That isn't pseudocode, as people have already told you. But it isn't assembly either. You would have to ask your lecturer for an explanation and what language that is. Please use the code button, which will preserve any indentation in the original code, and will by magic make that code intelligible. That last bit was a lie But the code button will make it look better.
 
Marshal
Posts: 6134
418
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@OP
I must say you were very brave to even attempt this exercise or maybe prank (which feels more of the case).

What is the module/class name? Which language is being used there?
 
Joxsel Marico
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

That isn't pseudocode, as people have already told you. But it isn't assembly either. You would have to ask your lecturer for an explanation and what language that is. Please use the code button, which will preserve any indentation in the original code, and will by magic make that code intelligible. That last bit was a lie But the code button will make it look better.



hello thank for reply as im new here and first time I received these negative comment for so I dont know all function here,first about pseudcode,this is really pseudocode,I have attached the pseduo,second about the lecturer,my lecturer is math expert,he said that we can translate either c++ or java.
pseduo.png
[Thumbnail for pseduo.png]
 
Joxsel Marico
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:@OP
I must say you were very brave to even attempt this exercise or maybe prank (which feels more of the case).

What is the module/class name? Which language is being used there?




thank for reply,this is my first time I joined and posted here.And you said that,I have thought before I posted my work here if not I wont register this website,this is not prank.

the class called ModFalsePos,im using java
 
Joxsel Marico
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:That's not pseudocode.
It's pretty much unintelligible.
Looks more like some form of assembly.



thank for your words,my java is not good but im still practice thought,I have posted the pseduocode image which I took from my pdf that given by my lecturer
 
Joxsel Marico
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:Well, that pseudocode is impossible to make sense in a reasonable amount of time as. What is it supposed to do? What do the 7 parameters do?

Not so humorous aside: if a method has 7 parameters, it's probably missing a few more.




you mean the 7 ? its an algorithm for count assume that f(x)=x^5-7

note : my english is bad apology
 
Campbell Ritchie
Marshal
Posts: 60867
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Despite what your lecturer says, that isn't pseudocode. Please explain what the modified false positive method is supposed to do, and also what these seven variables mean: xl, xu, es, imax, xr, iter, and e
 
Joxsel Marico
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Despite what your lecturer says, that isn't pseudocode. Please explain what the modified false positive method is supposed to do, and also what these seven variables mean: xl, xu, es, imax, xr, iter, and e


I hardly to explain about modified false position but the only I know is to find the truue value root from given function,f(x)  x^5-7
x1 =1
x2 =6

the pseduocode that shown it will print out like this,including the true value of root :

picture taken on https://nptel.ac.in/courses/122104019/numerical-analysis/Rathish-kumar/ratish-1/f3node4.html
modified.png
[Thumbnail for modified.png]
 
Campbell Ritchie
Marshal
Posts: 60867
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Iron Nokana wrote:. . . I hardly to explain about modified false position . . .

I am afraid, I think you do need to explain what the modified false position algorithm is supposed to do. Most of us are not experts in numerical methods and don't know anything about that algorithm.

picture taken on https://nptel.ac.in/courses/122104019/numerical-analysis/Rathish-kumar/ratish-1/f3node4.html

Now, that is pseudocode. It appears to be called the Regula Falsi method, which sounds as though it had been invented by two people in Italy. The name of the method seems to change from link to link. That pseudocode is however incomplete. It doesn't, for example, tell us what the convergence criterion in line 2 is. I would suggest you decide on a convergence criterion, which must be consistent with the precision of the datatypes you are using, and create a method to implement that. Maybe you should call it needsToConverge, and this is a possible implementation:-If the old result is 123.4567 and the new result is 123.4444 and the proportion is 0.000001 (=10⁻⁶), then you are not within the convergence criterion and it will return true. You will obviously have your own convergence criterion. Remember the precision limits of doubles, particularly if you approach (±)Double#MAX_VALUE and even more so if the absolute value of your number is ≤Double#MIN_NORMAL.
 
Dave Tolls
Master Rancher
Posts: 3677
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Despite what your lecturer says, that isn't pseudocode. Please explain what the modified false positive method is supposed to do, and also what these seven variables mean: xl, xu, es, imax, xr, iter, and e



Possibly some sort of mathematical pseudocode?
Though the lack of explanation inside the code doesn't help.
 
Campbell Ritchie
Marshal
Posts: 60867
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:. . . Possibly some sort of mathematical pseudocode? . . .

Still totally incomprehensible to anybody unfamiliar with that algorithm. I could understand something like Σx, but there isn't even anything like that in it

That link is caused by somebody not understanding what pseudocode is, then adding things like Σx to it as shorthand to write on the board, then somebody else deciding to give it a name. You end up with something different from pseudocode called pseudocode. But even the example in Wikipedia is much easier to understand than what we have here.

[edit]Move, “ as shorthand” into its correct location.
 
Dave Tolls
Master Rancher
Posts: 3677
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wil admit to it being a bit of a strech.
 
Joxsel Marico
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Iron Nokana wrote:. . . I hardly to explain about modified false position . . .

I am afraid, I think you do need to explain what the modified false position algorithm is supposed to do. Most of us are not experts in numerical methods and don't know anything about that algorithm.

picture taken on https://nptel.ac.in/courses/122104019/numerical-analysis/Rathish-kumar/ratish-1/f3node4.html

Now, that is pseudocode. It appears to be called the Regula Falsi method, which sounds as though it had been invented by two people in Italy. The name of the method seems to change from link to link. That pseudocode is however incomplete. It doesn't, for example, tell us what the convergence criterion in line 2 is. I would suggest you decide on a convergence criterion, which must be consistent with the precision of the datatypes you are using, and create a method to implement that. Maybe you should call it needsToConverge, and this is a possible implementation:-If the old result is 123.4567 and the new result is 123.4444 and the proportion is 0.000001 (=10⁻⁶), then you are not within the convergence criterion and it will return true. You will obviously have your own convergence criterion. Remember the precision limits of doubles, particularly if you approach (±)Double#MAX_VALUE and even more so if the absolute value of your number is ≤Double#MIN_NORMAL.

I see,does regular false method and modified false method are different ?
 
Joxsel Marico
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Dave Tolls wrote:. . . Possibly some sort of mathematical pseudocode? . . .

Still totally incomprehensible to anybody unfamiliar with that algorithm. I could understand something like Σx, but there isn't even anything like that in it

That link is caused by somebody not understanding what pseudocode is, then adding things like Σx to it as shorthand to write on the board, then somebody else deciding to give it a name. You end up with something different from pseudocode called pseudocode. But even the example in Wikipedia is much easier to understand than what we have here.

[edit]Move, “ as shorthand” into its correct location.

actually this is true because im lack of understanding pseducodeIn my collge my lecturer never teach us about pseducode,just basic programming,except some subject has a lesson about code in pseducode,I dont have choice but force to learn and study,so im apology if I posted it
 
Campbell Ritchie
Marshal
Posts: 60867
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joxsel Marico wrote:. . . I see,does regular false method and modified false method are different ?

What regular false method? It says Regula Falsi method in the links you have supplied. If you search for that title you may find out more information.

Donn't quote the whole of previous posts; only quote the relevant parts.
 
Ranch Hand
Posts: 59
6
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you copied the psedocode correctly in the original post? Sometimes pdfs can substitute characters when copying text from them.

I found this link which has similar code:

http://www.robotics.sei.ecnu.edu.cn/learning/NMethods/lecturenotes/Bracketing.doc

But instead of lines like:




It has:



It would make a lot more sense with these characters being replaced.
 
Tim Moores
Saloon Keeper
Posts: 4870
117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sresh Rangi wrote:It would make a lot more sense with these characters being replaced.


+1. Could also be the result of OCR having been used but the result not having been proofread.
 
Campbell Ritchie
Marshal
Posts: 60867
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sresh Rangi wrote:. . . It would make a lot more sense with these characters being replaced.

Yes, it does . That .doc link you posted shows obvious implemented code. Don't know what language it is. It looks like something procedural, but that is a much less serious problem. Working out what the ~= operator means would also help; I suspect it means, “is approximately equal to”.
 
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Working out what the ~= operator means would also help; I suspect it means, “is approximately equal to”.



Or it could mean "is not equal to"... the ~ character is commonly used by mathematicians as the "not" operation. So yeah... we need to know what it really means.
 
Joxsel Marico
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Campbell Ritchie wrote:Working out what the ~= operator means would also help; I suspect it means, “is approximately equal to”.



Or it could mean "is not equal to"... the ~ character is commonly used by mathematicians as the "not" operation. So yeah... we need to know what it really means.



well I tried to translate the pseducode as possible as I can,this is my first attempt to try translate apology
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!