This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

maths and functions

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Morning I did two exercises and in both  i make some mistakes.I dont know what i did wrong.If something is missing or not .

first exercise

I have a = -1.5, b = 1.5, h = 0.1.We use this variables  x from a until b with "step" h (its a for loop ).After i have this [deleted link] and i will  printf the variables x,y.The program  will be finished when x is bigger than b.
what i did :


first exercise
we read  x and n( the number of term will be used).We give 1 to the variable i.We give 1 in the variable term.We give the variable 1 to myexp.For each term i=1...n.we calculate each term from previous with the use of reduction type term<--term*x/i.We add the new term on myexp.We printf the x,myexp and exp(x).

what i did:
 
Marshal
Posts: 79979
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please tell us the full details; we can only help if we know what is going wrong. What is supposed to happen and what does happen? I think I can see a compiler error somewhere. Add the image to the post, not the link (which I shall delete) because some people are reluctant to click such links. Please explain what the formula is supposed to calculate.
 
Campbell Ritchie
Marshal
Posts: 79979
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the actual code with correct formatting (see suggestions here). You need to be able to read the code yourself, and incorrect indentation will stop you reading it. Go through the error messages from the compiler first. Why are you mixing int arithmetic and double arithmetic? Please explain what the loops mean.
 
akol ompen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please tell us the full details; we can only help if we know what is going wrong. What is supposed to happen and what does happen? I think I can see a compiler error somewhere. Add the image to the post, not the link (which I shall delete) because some people are reluctant to click such links. Please explain what the formula is supposed to calculate.


i cant edit my code .I did something on it some changes.If i understand good i am not permited to put link (sorry i didnt knew that) and i tryed find how to put image from my pc to the post but i didnt managed to.In any case i will do again if i am somewhere false.Whats its going on this exercise is that it cant be run properly.What i mean is that on  dev-c++ i press up complile & run and it is doing a calculate 0y= that is never finished.What it should do is to show only some numbers.
 
akol ompen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please tell us the full details; we can only help if we know what is going wrong. What is supposed to happen and what does happen? I think I can see a compiler error somewhere. Add the image to the post, not the link (which I shall delete) because some people are reluctant to click such links. Please explain what the formula is supposed to calculate.

in the second exercise

i dont think is right i think i have done mistakes. On dev-c++ i take this messages.Expected primary -expression before int.j not declared and i was not declared.Its too difficult this exercisee .I dont know what am i doing wrong
 
Campbell Ritchie
Marshal
Posts: 79979
397
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's stick to the first exercise. You have started by posting unformatted code which needs a lot of translation to make any sense of. Go and copy the code with indentation and spaces surrounding all binary operators. You need to be able to read your code more than I do.
Don't try to explain what is obvious, like having to declare the variables.
Go to line 20. Work out the values of b and x at the start of that loop. Where are those values changed? What will happen to the loop once you start running it?
Why are you using pow(x, 2)? I have already told you to use x * x instead.
Why are you mixing integer and floating‑point arithmetic? What happens if you try to assign a value with fractions to an integer?
 
Campbell Ritchie
Marshal
Posts: 79979
397
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please read about abs(). Who told you to use it? It is not appropriate for the current application.
Please post the original image with the formula; I removed the link for reasons I explained earlier. I can see it, and I think it evaluates to
1.0 ÷ √(|x² − 1.0|)
in which case when x = ±1, the formula will evaluate to ∞.

What is it the formula for?

I haven't looked at the second exercise yet.
 
akol ompen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please read about abs(). Who told you to use it? It is not appropriate for the current application.
Please post the original image with the formula; I removed the link for reasons I explained earlier. I can see it, and I think it evaluates to
1.0 ÷ √(|x² − 1.0|)
in which case when x = ±1, the formula will evaluate to ∞.

What is it the formula for?

I haven't looked at the second exercise yet.


"indentation and spaces surrounding all binary operators" i didnt catch it.If you could do an example please.What i think you mean is that i do lines with out wrote something? .Next,I go to line 20 probably you reffer to  fro loop.The variable b is standar i think it doesnt change its b=1.5 the variable x is changing with x=x+h until this will be bigger than the number b.I used pow(x,2) because thats what they told me ,sorry i will fix it.My mistake I will doing it double.I dont know what will happen but its not good as far as i know and from java.Abs() is need on this exercise,why isnt appropriate?i think i should declare #define f(x) 1.0 ÷ √(|x² − 1.0|) but i am not sure about that.I agree 1.0 ÷ √(|x² − 1.0|) this is it  and that x = ±1.The formula is just an exercise to appear the  results of y .
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

akol ompen wrote:
"indentation and spaces surrounding all binary operators" i didnt catch it.If you could do an example please.What i think you mean is that i do lines with out wrote something?



Which is more readable? understandable?

This? ....

                       

Or this? ...

 

Also, your eariler code had comments. Why did you remove them? Granted, they might not have been the best comments, but you could have improved them, than removing them completely.

Henry
 
akol ompen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

akol ompen wrote:
"indentation and spaces surrounding all binary operators" i didnt catch it.If you could do an example please.What i think you mean is that i do lines with out wrote something?



Which is more readable? understandable?

This? ....

                       

Or this? ...

 

Also, your eariler code had comments. Why did you remove them? Granted, they might not have been the best comments, but you could have improved them, than removing them completely.

Henry

I understand! Thanks a lot now i catch it i will do it
 
akol ompen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

akol ompen wrote:

Henry Wong wrote:

akol ompen wrote:
"indentation and spaces surrounding all binary operators" i didnt catch it.If you could do an example please.What i think you mean is that i do lines with out wrote something?



Which is more readable? understandable?

This? ....

                       

Or this? ...

 

Also, your eariler code had comments. Why did you remove them? Granted, they might not have been the best comments, but you could have improved them, than removing them completely.

Henry

I understand! Thanks a lot now i catch it i will do it
i will do and the next exercise after .Lets finish this.

 
Campbell Ritchie
Marshal
Posts: 79979
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:. . . . Which is more readable? understandable?


I would have written this:-As I explained earlier, that is not correct code, but at least formatted correctly. You need to use the formatting to make the code legible to yourself.
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic