Autor Beitrag
CSMN
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 43
Erhaltene Danke: 2



BeitragVerfasst: Do 05.08.10 15:26 
wenn du den wert 0,01154 [V] als value nimmst, was ist dann das sollergebnis und das istergebnis? in welchen case springt das program? und welcher wert ergibt sich durch Math.Log10(value) / 3?
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Do 05.08.10 15:28 
bei 0,01154 ist es 10^-1 , -1 / 3 = -0,3333 ~ -1 springt in case -1
richtig?
CSMN
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 43
Erhaltene Danke: 2



BeitragVerfasst: Do 05.08.10 15:30 
und was sagt der debugger dazu? bestätigt er dir das?
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Do 05.08.10 15:31 
:D ja tut er^^
aber das ergebnis stimmt trotzdem nicht...
CSMN
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 43
Erhaltene Danke: 2



BeitragVerfasst: Do 05.08.10 15:36 
user profile iconIvy hat folgendes geschrieben Zum zitierten Posting springen:
:D ja tut er^^
aber das ergebnis stimmt trotzdem nicht...


also bei den code den du gepostet hast macht er das jedenfalls nicht!
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Do 05.08.10 15:39 
ja ich habs bei mir nochmal bissl umgeändert, immer wenn der value jetzt kleiner als 0 is rechnet er folgendes:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
if (value <= 1)
            {
                bedingung = (int)(value != 0 ? Math.Log10(value):0);
            }
            else
            {
                bedingung = (int)(value != 0 ? Math.Log10(value) / 3 : 0);
            }


damit funktionierts
CSMN
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 43
Erhaltene Danke: 2



BeitragVerfasst: Do 05.08.10 15:45 
und in welchen fällen stimmt das ergebnis nicht?
CSMN
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 43
Erhaltene Danke: 2



BeitragVerfasst: Do 05.08.10 15:48 
user profile iconIvy hat folgendes geschrieben Zum zitierten Posting springen:
ja ich habs bei mir nochmal bissl umgeändert, immer wenn der value jetzt kleiner als 0 is rechnet er folgendes:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
if (value <= 1)
            {
                bedingung = (int)(value != 0 ? Math.Log10(value):0);
            }
            else
            {
                bedingung = (int)(value != 0 ? Math.Log10(value) / 3 : 0);
            }


damit funktionierts


in den quelltext steht ab nicht kleiner als null sondern kleiner gleich eins...
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Do 05.08.10 15:48 
ja wenn ich jetz 0,0251236 eingeb kommt raus 2,51mV, gut die einheit stimmt jetzt ja schonmal aber als ergebnis sollte eigetnlich 25,124 rauskommen

ja sorry habs grad in 0 geändert, war noch nen versuch vorher^^
CSMN
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 43
Erhaltene Danke: 2



BeitragVerfasst: Do 05.08.10 15:56 
user profile iconIvy hat folgendes geschrieben Zum zitierten Posting springen:
ja wenn ich jetz 0,0251236 eingeb kommt raus 2,51mV, gut die einheit stimmt jetzt ja schonmal aber als ergebnis sollte eigetnlich 25,124 rauskommen

ja sorry habs grad in 0 geändert, war noch nen versuch vorher^^


na dann hauste wohl eine stelle zuviel weg ^^
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Do 05.08.10 16:03 
user profile iconCSMN hat folgendes geschrieben Zum zitierten Posting springen:
user profile iconIvy hat folgendes geschrieben Zum zitierten Posting springen:
ja wenn ich jetz 0,0251236 eingeb kommt raus 2,51mV, gut die einheit stimmt jetzt ja schonmal aber als ergebnis sollte eigetnlich 25,124 rauskommen

ja sorry habs grad in 0 geändert, war noch nen versuch vorher^^


na dann hauste wohl eine stelle zuviel weg ^^


hm ja scheint so, aber wo und warum weiß ich noch nicht^^
CSMN
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 43
Erhaltene Danke: 2



BeitragVerfasst: Do 05.08.10 16:13 
^^... du wirst es schon finden...
wenn nicht kannst ja später nochmal ne komplette version deines codes posten...
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Fr 06.08.10 09:34 
hmm.. also ich hab keine ahnung warums nicht geht, hier nochmal der komplette code:

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
public string ConvertTo(double value, int significance, string unit, bool usePrefix)
        {
             unit = "V";
            string prefix = "";
            double devisor = 1;
            int bedingung = 0;
            if (value <= 1)
            {
                bedingung = (int)(value != 0 ? Math.Log10(value):0);
            }
            else
            {
                bedingung = (int)(value != 0 ? Math.Log10(value) / 3 : 0);//123456,78/3=1,697 ~1
            }

            switch (bedingung) 
            {                
                case -5:
                    prefix = "f";
                    devisor = 10e-14;
                    break
                case -4:
                    prefix = "p";
                    devisor = 10e-11;
                    break;
                case -3:
                    prefix = "n";
                    devisor = 10e-8;
                    break;
                case -2:
                    prefix = "µ";
                    devisor = 10e-5;
                    break;
                case -1:
                    prefix = "m";
                    devisor = 10e-3;
                    break;
                case 1:    //Springt in case 1
                    prefix = "k";
                    devisor = 10e2;
                    break;
                case 2:
                    prefix = "M";
                    devisor = 10e5;
                    break;
                case 3:
                    prefix = "G";
                    devisor = 10e8;
                    break;
                case 4:
                    prefix = "T";
                    devisor = 10e11;
                    break;
                default:
                    prefix = "";
                    devisor = 1;
                    break;
            }
            if (!usePrefix && devisor < 1)
            {
                //Ergebnis ohne Prefix
            }
            else
            {
               //return rad.ToString();
            }
           
            //Signifikante Stellen
            double  ergebnis = Math.Pow(10, -Math.Floor(Math.Log10(value) + significance -1)); //(123456,78)+4-1= 10e-2 =0,01
            double rvalue = Math.Round(value * ergebnis,significance+1) / ergebnis; //(123456,78*0,01)/0,01= 123500
                        
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append(rvalue / devisor); 
            sb.Append(prefix); //k
            sb.Append(unit); //V
            return sb.ToString();  //---->123,5kV 
            
        }


Zuletzt bearbeitet von Ivy am Mo 30.08.10 11:26, insgesamt 1-mal bearbeitet
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Mo 30.08.10 11:10 
keiner ne idee warum? :( bin solangsam echt am verzweifeln

ich habe folgende ausgaben:

Wert: 2,51236
Sig.: 3
Erg: 2,51V RICHTIG

Wert: 2,51236
Sig.: 5
Erg: 2,51V FALSCH eig 2,5124V

Wert: 0,251236
Sig.: 3
Erg: 0,251V FALSCH eig 0,251mV

Wert: 0,0251236
Sig.: 5
Erg: 2,51mV FALSCH eig 25,124mV

Wert: 251236
SIg.: 3
Erg.: 2,51MV RICHTIG
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Mo 30.08.10 13:32 
Das Runden kann so nicht funktionieren, versuch es lieber so:
ausblenden C#-Quelltext
1:
2:
double lastSignificantDigit = Math.Pow(10, (int)(Math.Log10(value) - significance));
double rvalue = Math.Round(value / lastSignificantDigit) * lastSignificantDigit;


Dann wären da noch ein paar Punkte, die dir im Debugger wirklich hätten auffallen müssen, wenn du dich mit der Mathematik dahinter auseinandersetzen würdest:
  • Das Teilen des Logarithmus durch 3 muss natürlich in beiden Fällen drin bleiben (es ist also überhaupt keine Fallunterscheidung nötig), schließlich sind es in beide Richtungen 10³-Schritte.
  • Das Ergebnis dieser Division muss erst einmal mit Math.Floor abgerundet werden
  • 10^-3 != 10e-3 :!:


PS: Ein StringBuilder ist hier unnötig, nimm string.Format oder einfach "+". Und es heißt Divisor ;) .

_________________
>λ=
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Mo 30.08.10 13:41 
user profile iconKha hat folgendes geschrieben Zum zitierten Posting springen:


  • Das Teilen des Logarithmus durch 3 muss natürlich in beiden Fällen drin bleiben (es ist also überhaupt keine Fallunterscheidung nötig), schließlich sind es in beide Richtungen 10³-Schritte.
  • Das Ergebnis dieser Division muss erst einmal mit Math.Floor abgerundet werden
  • 10^-3 != 10e-3 :!:




Das mit dem durch 3 hatte mir mein Chef so gesagt^^ naja habs wieder rausgenommen
Welche Division meinst du? diese?!
ausblenden C#-Quelltext
1:
 ^(int)(value != 0 ? Math.Log10(value) / 3 : 0)					


10^-3 != 10e-3??? 10e-3 ist doch das selbe wie 10^-3 :?:
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Mo 30.08.10 13:44 
user profile iconIvy hat folgendes geschrieben Zum zitierten Posting springen:
10^-3 != 10e-3??? 10e-3 ist doch das selbe wie 10^-3 :?:

Nein, 10e-3 = 10x10^-3 != 10^-3.
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Mo 30.08.10 13:51 
ahja... habs jetz mal überall geändert, aber jetzt kommen noch komischere zahlen raus :/
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Mo 30.08.10 14:14 
user profile iconIvy hat folgendes geschrieben Zum zitierten Posting springen:
Welche Division meinst du? diese?!
Jupp. Aus 0,2 soll ja 200e-3 werden. lg(0,2) ist -0.69..., durch 3 und abgerundet -1, also milli.

user profile iconIvy hat folgendes geschrieben Zum zitierten Posting springen:
ahja... habs jetz mal überall geändert, aber jetzt kommen noch komischere zahlen raus :/
Aber hoffentlich nicht an den Stellen, die schon korrekt waren (10e2 z.B.)?
Mit meinen vier Vorschlägen habe ich für deine Beispiele jedenfalls die richtigen Zahlen herausbekommen.

_________________
>λ=
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Mo 30.08.10 14:28 
achso nur bei den negativen werten??

hab jetz die math.floor so eingebunden.
ausblenden C#-Quelltext
1:
 value = Math.Floor(Math.Log(bedingung));					

kommt aber als ausgabe was ganz komisches "n. def .V"