[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
What can cause a numerical simulation in C code to misbehave?
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 12
Thread images: 2
File: rei.jpg (8 KB, 300x168) Image search: [Google]
rei.jpg
8 KB, 300x168
What can cause a numerical simulation in C code to misbehave?

For example I a certain behaviour with a set of parameters.
Then, I change the stiffness of a spring or the value of damping (keeping then physically coherent) and I get a crazy response that don't correspond with the experimental results.

I use double instead of float and none of the variable overflows.

What am I overlooking?
>>
>>51806423
Bruh do you even dt
>>
>>51806705
What do you mean by dt?
>>
>What could cause a numerical simulation in C code to misbehave

Anything involving floating point arithmetic
Anything involving built in integer types that may overflow.

And just for further emphasis, do not use floating point arithmetic for anything that needs absolute accuracy.

Also, make sure you're not reading the wrong memory addresses. That could fuck things up too.
>>
>>51807195
>And just for further emphasis, do not use floating point arithmetic for anything that needs absolute accuracy.
What do you recommend, then?
>>
>>51806423
Try arbitrary precision integer / decimal maths only.
>>
Do verlet integration
>>
>>51806423
>What may cause C to throw a fit he asks...

What won't is the correct question.
Anyhow, before compiling, have you done at least the basics? Prayed to assembly jesus? Sacrificed 3 ram sticks to the dark gods and install win10 on a sacrificial goat of a friend's pc?

If not wtf man?
>>
>>51807376
He mistakenly installed win10 on his own computer and a NSA indian underage faggot acessed his code, and changed some variables thus resulting on a catastrophic error on his physics engine.
>>
>>51807195
I am usind double precision (double) so the rounding errors should have a negligible influence (the operations don't always deal with *very* close values)

>make sure you're not reading the wrong memory addresses
My code is just additions multiplications and divisions of doubles. I don't think the mistake is hiding behind this point.

>>51807261
Verlet integration uses central difference (so the value at the step k+1, which is not yet computed). But I have a very small sampling time so I think Euler might do the job.

>>51807376
>Anyhow, before compiling, have you done at least the basics? I run some experiments already. The code seems to work when implemented on a micro controller but the same operations when asked to interact with a virtual environment (the simulation) is shitting the bed.
I use linux (ubuntu) and gcc to compile.
>>
File: 1442508131085.jpg (136 KB, 960x1280) Image search: [Google]
1442508131085.jpg
136 KB, 960x1280
>>51807504
Consider using GNU emacs
>>
>>51807504
If you can share the code I'll look at it. If you can't the fuck off
Thread replies: 12
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.