Andreas Korthaus: Mathematik: Wie erstelle ich Skala mit "runden" Einträgen?

Beitrag lesen

Hallo!

Wirklich nicht so einfach das ganze, aber ich glaube mit Deiner Hilfe habe ich eine Idee:

ich schreibe das mal so grob als "pseudeo-programm" (Richtung PHP ;-)

//Ausgangswert
$min =  1790;
$max = 2187;

// Differenz
$diff = $max - $min;
$diff_prozent = $diff / $max;

$absolut_max = $max + 0,1 * $diff;
$absolut_min = $min - 0,1 * $diff;
$diff_max = $absolut_max - $absolut_min;

// Ermittlung einer Zahl mit möglichst vielen Nullen am Ende zw. $max und $absolut_max
for($i=1, $i < count_chars($absolut_max), $i++) {
    $temp = substr($absolut_max,0,-$i).str_repeat ( "0", $i);
    if ($temp>$max) {
        $max_gerundet = $temp;
    } else {
        break;
    }
}

// Ermittlung einer Differenz mit möglichst vielen Nullen am Ende zw. $diff_max und $diff
for($i=1, $i < count_chars($diff_max), $i++) {
    $temp = substr($diff_max ,0,-$i).str_repeat ( "0", $i);
    if ($temp>$diff) {
        $opt_diff = $temp;
    } else {
        break;
    }
}

$schritte = abs($opt_diff/10);

// Erstelle einen Array mit den einzelnen Skala-Werten
for($i=0, $i < 10, $i++) {
    skala_array[]=$max_gerundet - $i * $schritte;
}

Was sagst Du dazu? Wie könnte man das noch verbessern?

Viele Grüße
Andreas