Need some beginner books( C I think).
Page 1 of 1
Atropa




Posts: 878

PostPosted: Wed, 15th Dec 2010 12:40    Post subject: Need some beginner books( C I think).
Hey guys! Smile
Ok so the time has come for me to learn how to program. What I need programming for is to solve differential equations(with boundary conditions if that makes any difference) and writing simulations(propably simple though).

I was thinking about learning C for this. Wouldn't that work rather well? I often stumple upon physics proffesors using fortran but I don't think I want that(or do I?).

If there exist some C beginner book with examples from physics then it would be spot on!
Back to top
Guy_Incognito




Posts: 3423

PostPosted: Wed, 29th Dec 2010 00:24    Post subject:
Well, C is not perfectly suitable for such mathematics. What you need is Matlab, which is technically a scripting language, but it's ideal for your needs, especially for algebra calculations. You can easily perform tasks such as differentiation and integration, which are not so easy to implement in other general or system-programming languages.
Back to top
BearishSun




Posts: 4484

PostPosted: Wed, 29th Dec 2010 00:32    Post subject:
If you use matlab you'll get everything done for you, which I don't think is what you want?

Personally I have never used Fortran but I have heard it get a lot of praise for math and physics stuff, and it's still widely used language in certain circles.

If you decide with C however, maybe the best way to start is some tutorials on the net. They're usually easier to understand than books in my experience.
Back to top
dingo_d
VIP Member



Posts: 14555

PostPosted: Wed, 29th Dec 2010 00:43    Post subject:
Fortran is used somewhat because it's really fast when it comes to math stuff. But these days ppl are using more and more C and C++.

On my uni tho the popular stuff is Python. And it's not complicated...


"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson
chiv wrote:
thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found.

Back to top
Atropa




Posts: 878

PostPosted: Wed, 29th Dec 2010 12:31    Post subject:
I know about matlab but I was looking for a better understanding of how to implement math on computers. BearishSun if you happen to have some links to tutorials with examples I can use, then please share Smile
At the moment I've just started to read "The C programming language" and after that I will try to see if I can get something out of "Numerical Recipies". Hopefully this will work out well. It's a bit more time consuming than I hoped Sad
Back to top
Werelds
Special Little Man



Posts: 15098
Location: 0100111001001100
PostPosted: Wed, 29th Dec 2010 13:06    Post subject:
Well the biggest problem with math is that you have to be smart about the types you use. There are tons of numerical types, but which one do you want to use in what situation? It's a bit easier in weakly typed languages, where the interpreter or compiler handles the type conversions implicitly Smile

And then there's the problem that not every "basic" math operation is necessarily directly available in a language; try 6^2 in C and watch it fail Wink
Back to top
Atropa




Posts: 878

PostPosted: Wed, 29th Dec 2010 13:32    Post subject:
Well making a function which takes to integers as input(n=6, m=2) and multiplies n with itself m times shouldn't be that hard to make. I see your point though.
I was thinking that if you understand how the computer calculates, it will be easier to guess uncertainties on your result and figure out where to write improvements.
Back to top
Werelds
Special Little Man



Posts: 15098
Location: 0100111001001100
PostPosted: Wed, 29th Dec 2010 13:40    Post subject:
Atropa wrote:
Well making a function which takes to integers as input(n=6, m=2) and multiplies n with itself m times shouldn't be that hard to make. I see your point though.
I was thinking that if you understand how the computer calculates, it will be easier to guess uncertainties on your result and figure out where to write improvements.

Well you don't have to for this one for example, it's in the standard libraries so you just need to include the correct header. It's something you gotta be aware of though Smile

I suggest you dig into data types first and foremost - I assume the math itself won't be that hard for you. Most language use pretty much the same size and precision for things like doubles and floats (some languages have more, and some don't care), so if you understand the basic principle and differences for one language you'll get it in other languages as well; it may be slightly different in practice, but the principle is always the same. For that, C is a good place to learn it in, as it's completely unforgiving Razz
Back to top
BearishSun




Posts: 4484

PostPosted: Wed, 29th Dec 2010 13:49    Post subject:
Atropa I think this should be a good start for C++:

http://www.learncpp.com/ (C++ is a superset of C, so if you know C++ you know C as well, plus is has some other handy features)

Also be aware that higher level languages like C#, Python or Java (C# being my preference) are much easier to learn than C/C++ because they hide a lot of the background details. For anything but the largest and most performance intensive apps, those languages are a much better choice.

However, I suppose there isn't a lot of math or physics stuff done in C# as there is in C++. So it might be a bad choice for the reason that you might not be able to understand other peoples work if you only know C#.
Back to top
Werelds
Special Little Man



Posts: 15098
Location: 0100111001001100
PostPosted: Wed, 29th Dec 2010 15:21    Post subject:
BearishSun wrote:
(C++ is a superset of C, so if you know C++ you know C as well, plus is has some other handy features)

It's the other way around. If you know C++, you definitely don't know C. For example, in C++ you're not gonna use pointers or malloc unless you really have to (and for good reason). The other way around you'll understand how much of C++ works internally, even though you don't need to do it yourself anymore. You'd be surprised at how many people who know some basic C++ and use vectors or maps, but don't have a clue what a pointer is Wink

Purely for the math, it really doesn't matter which language you choose. It can be done just as fine in C# or Java as it can be in C or C++ - they might be a bit slower depending on the situation, but they don't lack any mathematical power.

My advice: take one of the higher level languages. As a beginner doing some basic math stuff, there's no reason to learn what pointers are or how to manage memory yet. I'd also go for C#, as bloated as .NET can be, C# is a pleasant language for beginners. Once you're used to this stuff, you still should go all the way down to C though, because then you'll understand how much of the built-in classes and utilities work in the higher level languages Smile
Back to top
BearishSun




Posts: 4484

PostPosted: Wed, 29th Dec 2010 15:28    Post subject:
pwerelds wrote:
BearishSun wrote:
(C++ is a superset of C, so if you know C++ you know C as well, plus is has some other handy features)

It's the other way around. If you know C++, you definitely don't know C. For example, in C++ you're not gonna use pointers or malloc unless you really have to (and for good reason). The other way around you'll understand how much of C++ works internally, even though you don't need to do it yourself anymore. You'd be surprised at how many people who know some basic C++ and use vectors or maps, but don't have a clue what a pointer is Wink


? What are you talking about?

If you know C++, you know C. There's no other answer. If you don't know pointers, then you dont know C++.

I never learned C in my life, only C++. Every C++ book/tutorial teaches you about pointers extensively. You can't use C++ properly without knowing pointers so I don't know what you're talking about. References can be used instead of pointers, but they're more of a syntax convenience, and you still need to understand the underlying logic.


Last edited by BearishSun on Wed, 29th Dec 2010 15:29; edited 1 time in total
Back to top
Werelds
Special Little Man



Posts: 15098
Location: 0100111001001100
PostPosted: Wed, 29th Dec 2010 15:40    Post subject:
A reference is hardly the same as a pointer. Aside from the difference in syntax, indexing is done differently, a pointer can be NULL, and so on. References are also easier to understand and are extensively used in languages like PHP.

And I highly doubt any C++ tutorial shows you *alloc()/free() (I don't know, never used any tutorial for C++).
Back to top
BearishSun




Posts: 4484

PostPosted: Wed, 29th Dec 2010 15:46    Post subject:
they show you "new", and "delete", which are c++ equivalents of malloc/free. If you have never heard of new/delete then I really doubt you should be discussing this.

I never said they are the same, I said even if you only use references you will learn to understand how pointers work if you want to use references without getting confused.
Back to top
Werelds
Special Little Man



Posts: 15098
Location: 0100111001001100
PostPosted: Wed, 29th Dec 2010 16:40    Post subject:
Yeah because just like new malloc also calls constructors, free just like delete also calls destructors, and there's an equivalent of realloc. Notice how I said *alloc, not just malloc Wink

The differences aren't big, but they are there, and you don't use realloc in C++ like you would in C. There are other means to achieve the same thing, but there is quite a big difference between what new/delete delete do as opposed to malloc/free. Comes with the nature of the language obviously, but the difference is hardly as trivial as you make it sound.

And nice try, but I never said I don't know C++, I just said I never used a tutorial for it. Having worked in fuck knows how many languages, I didn't really need tutorials. I already knew the OO principles, and I had worked in C before, so combining the knowledge of the 2 was plenty to dive straight into C++ Smile


Anyway, let's drop it, we're derailing like crazy here Wink
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group