Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Auf_Entladen_Kondesator
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         /*
  16.         Aufladen: Uc = U * (1-e ^ -(t/(R*C)))       nach t: t = ln(1 - (Uc/U) * (-tau)      ln -> math.log10
  17.         Entladen: Uc = U * e ^ -(t/(R*C))
  18.         */
  19.  
  20.         public Form1()
  21.         {
  22.             InitializeComponent();
  23.             BackColor = Color.LightBlue;
  24.             listBox1.Items.Add("t in μs \t U in V\n");
  25.            
  26.         }
  27.  
  28.         private void Ende_Click(object sender, EventArgs e)
  29.         {
  30.             this.Close();
  31.         }
  32.  
  33.         private void Rechnen_Click(object sender, EventArgs e)
  34.         {
  35.             double Tau;
  36.             double Uc;
  37.             int Zeit = 0;
  38.  
  39.             double U;//=Convert.ToDouble(EingabeVolt.Text);
  40.             bool KonvertU = double.TryParse(EingabeVolt.Text, out U);
  41.  
  42.             double R;//= Convert.ToDouble(EingabeWiderstand.Text);
  43.             bool KonvertR = double.TryParse(EingabeWiderstand.Text, out R);
  44.  
  45.             double C;// = Convert.ToDouble(EingabeUFahr.Text);
  46.             bool KonvertC = double.TryParse(EingabeUFahr.Text, out C);
  47.  
  48.             double AnzahlWerte5=5,AnzahlWerte10=10,AnzahlWerte50=50;
  49.            
  50.            
  51.             Tau = Convert.ToDouble(EingabeWiderstand.Text) * Convert.ToDouble(EingabeUFahr.Text);
  52.             AusgabeTau.Text = Convert.ToString(Tau);
  53.                    
  54.  
  55.             if (KonvertU==true && Anzahl5.Checked == true && Aufladung.Checked == true)
  56.             {
  57.                 for (int i = 0; i < AnzahlWerte5; i++)
  58.                 {
  59.                     Uc = U * (1 - (Math.Pow(Math.E, -(Zeit / (R * C)))));
  60.                     //Uc = Math.Round(Uc, 2);
  61.                     listBox1.Items.Add(Convert.ToString(Zeit) + "\t" + Convert.ToString(Uc));
  62.                 }
  63.             }
  64.             else if (this.EingabeVolt.Text != "" && Anzahl10.Checked == true && Aufladung.Checked == true)  //!string.IsNullOrEmpty(this.EingabeVolt.Text)
  65.             {
  66.                 for (int i = 0; i < AnzahlWerte10; i++)
  67.                 {
  68.                     //t = t + 1;
  69.                     Zeit = Zeit + 5000;
  70.                     Uc = U * (1-  (Math.Pow(Math.E, -(Zeit / (R * C)))));
  71.                     //Uc = Math.Round(Uc, 2);
  72.                     listBox1.Items.Add(Convert.ToString(Zeit) + "\t" + Convert.ToString(Uc));      //$"{Zeit.ToString()} \t {Uc}"
  73.                 }
  74.                
  75.             }
  76.             else if (this.EingabeVolt.Text != "" && Anzahl50.Checked == true && Aufladung.Checked == true)  
  77.             {
  78.                 for (int i = 0; i < AnzahlWerte50; i++)
  79.                 {
  80.                     //t = t + 1;
  81.                     Zeit = Zeit + 5000;
  82.                     Uc = U * (1 - (Math.Pow(Math.E, -(Zeit / (R * C)))));
  83.                     //Uc = Math.Round(Uc, 2);
  84.                     listBox1.Items.Add(Convert.ToString(Zeit) + "\t" + Convert.ToString(Uc));      
  85.                 }
  86.  
  87.             }
  88.             else if (this.EingabeVolt.Text!=""&& Anzahl5.Checked==true&& Entladung.Checked==true)
  89.             {
  90.                 for (int i = 0; i < AnzahlWerte5; i++)
  91.                 {
  92.                    
  93.                     Zeit = Zeit + 5000;
  94.                     Uc = U * (Math.Pow(Math.E, -(Zeit / (R * C))));
  95.                     //Uc = Math.Round(Uc, 2);
  96.                     listBox1.Items.Add(Convert.ToString(Zeit)+"\t"+Convert.ToString(Uc));
  97.                 }
  98.             }
  99.             else if(this.EingabeVolt.Text != "" && Anzahl10.Checked == true && Entladung.Checked == true)
  100.             {
  101.                 for (int i = 0; i < AnzahlWerte10; i++)
  102.                 {
  103.                     Uc = U * (Math.Pow(Math.E, -(Zeit / (R * C))));
  104.                     //Uc = Math.Round(Uc, 2);
  105.                     listBox1.Items.Add(Convert.ToString(Zeit) + "\t" + Convert.ToString(Uc));
  106.                 }
  107.             }
  108.             else if (this.EingabeVolt.Text != "" && Anzahl50.Checked == true && Entladung.Checked == true)
  109.             {
  110.                 for (int i = 0; i < AnzahlWerte50; i++)
  111.                 {
  112.                     Uc = U * (Math.Pow(Math.E, -(Zeit / (R * C))));
  113.                     //Uc = Math.Round(Uc, 2);
  114.                     listBox1.Items.Add(Convert.ToString(Zeit) + "\t" + Convert.ToString(Uc));
  115.                 }
  116.             }
  117.             else
  118.             {
  119.                 listBox1.Items.Add("Fehler");
  120.             }
  121.  
  122.  
  123.         }
  124.  
  125.         private void ClearList_Click(object sender, EventArgs e)
  126.         {
  127.             listBox1.Items.Clear();
  128.             listBox1.Items.Add("t in μs \t U in V\n");
  129.         }
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement