Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.
/* Assignment 2 - Question 2
Ed Macey - PT EEE - Student No. 2802204
Mob. 07811 185 749 Email edmacey@gmail.com
Determine the voltage across the resistor at given time intervals by using the below
equation. You enter the end time and the number of time steps required; the program will
determine the voltage at each of the time steps and stored in a text file, which can be
loaded into MATLAB and plotted.
Where Resistor R = 1e3 Ohms , Capacitor C = 1e-06 F, Applied voltage E = 10 volts. */
#include <iostream>
#include <stdio.h>
#include <math.h> // allows us to use more complex mathematical expressions in our programme
#include <fstream>
using namespace std;
//define all our variables and allocate values if known
double inputtime, timeintervals, nointervals, result, param, voltage;
double n = 0;
double R = 1000;
double C = 0.000001;
double E = 10;
int main()
{
//this writes the header text to data file
ofstream myfile;
myfile.open ("data.txt");
myfile << "Time interval,Voltage" << std::endl;
myfile.close();
//get input data
cout << "Voltage over time calc for a Resistive Capacitor" << std::endl;
cout << "___________________________________________________" << std::endl;
cout << "Please type in the total length of time in seconds," << std::endl;
cout << "ie 10 milliseconds would be 0.1 > ";
cin >> inputtime;
cout << "Please type in the number of time steps" << std::endl;
cout << "you would like > ";
cin >> nointervals;
timeintervals = inputtime / nointervals;
cout << nointervals;
cout << std::endl;
cout << std::endl;
//using do while we calculate the voltage at each interval step until there
//are no more interval steps left
do
{
n=n+timeintervals;
// this is the calculation
result =(exp (-(n/(R*C))));
voltage = result*E;
cout << "the voltage at " << n << " seconds is " << voltage << " volts" << std::endl;
// this prints the text to data file
ofstream myfile;
myfile.open ("data.txt", ios::app);
myfile << n << "," << voltage << std::endl; // we include the comma so that matlab can
// pick up the data as a comma delimeted text file
myfile.close();
}
while (n<inputtime);
cout << std::endl;
cout << std::endl;
cout << "Please load data.txt into Matlab to plot this data" << std::endl;
return 0;
}
/* Assignment 2 - Question 2
Ed Macey - PT EEE - Student No. 2802204
Mob. 07811 185 749 Email edmacey@gmail.com
Determine the voltage across the resistor at given time intervals by using the below
equation. You enter the end time and the number of time steps required; the program will
determine the voltage at each of the time steps and stored in a text file, which can be
loaded into MATLAB and plotted.
Where Resistor R = 1e3 Ohms , Capacitor C = 1e-06 F, Applied voltage E = 10 volts. */
#include <iostream>
#include <stdio.h>
#include <math.h> // allows us to use more complex mathematical expressions in our programme
#include <fstream>
using namespace std;
const double R = 1000;
const double C = 0.000001;
const double E = 10;
int main()
{
double inputtime, timeintervals, nointervals, param;
//get input data
cout << "Voltage over time calc for a Resistive Capacitor" << std::endl;
cout << "___________________________________________________" << std::endl;
cout << "Please type in the total length of time in seconds," << std::endl;
cout << "ie 10 milliseconds would be 0.1 > ";
cin >> inputtime;
cout << "Please type in the number of time steps" << std::endl;
cout << "you would like > ";
cin >> nointervals;
timeintervals = inputtime / nointervals;
cout << nointervals;
cout << std::endl;
cout << std::endl;
//this writes the header text to data file
ofstream myfile;
myfile.open ("data.txt");
myfile << "Time interval,Voltage" << std::endl;
//using do while we calculate the voltage at each interval step until there
//are no more interval steps left
for (double n = 0; n < inputtime; n += timeintervals)
{
// this is the calculation
double result =(exp (-(n/(R*C))));
double voltage = result*E;
cout << "the voltage at " << n << " seconds is " << voltage << " volts" << std::endl;
// this prints the text to data file
myfile << n << "," << voltage << std::endl; // we include the comma so that matlab can
// pick up the data as a comma delimeted text file
}
myfile.close();
cout << std::endl;
cout << std::endl;
cout << "Please load data.txt into Matlab to plot this data" << std::endl;
return 0;
}
/* Assignment 2 - Question 2
Ed Macey - PT EEE - Student No. 2802204
Mob. 07811 185 749 Email edmacey@gmail.com
Determine the voltage across the resistor at given time intervals by using the below
equation. You enter the end time and the number of time steps required; the program will
determine the voltage at each of the time steps and stored in a text file, which can be
loaded into MATLAB and plotted.
Where Resistor R = 1e3 Ohms , Capacitor C = 1e-06 F, Applied voltage E = 10 volts. */
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath> // allows us to use more complex mathematical expressions in our programme
#include <fstream>
#include <sstream>
const double R = 1000;
const double C = 0.000001;
const double E = 10;
using namespace std;
int main()
{
double inputtime=0;
double timeintervals, nointervals;
double x=0;
//get input data
cout << "Voltage over time calc for a Resistive Capacitor" << std::endl;
cout << "___________________________________________________" << std::endl;
do
{
cout << "Please type in the total length of time in seconds," << std::endl;
cout << "ie 10 milliseconds would be 0.1 > ";
string mystr;
getline (cin,mystr);
stringstream(mystr) >> inputtime;
}
while (inputtime<=0);
do
{
cout << "Please type in the number of time steps" << std::endl;
cout << "you would like > ";
cin >> nointervals;
}
while (nointervals<=0);
timeintervals = inputtime / nointervals;
cout << nointervals;
cout << std::endl;
cout << std::endl;
//this writes the header text to data file
ofstream myfile;
myfile.open ("data.txt");
myfile << "Time interval,Voltage" << std::endl;
//when the equation below is met n => inputtime then the calculation ceases
for (double n = 0; n < inputtime; n += timeintervals)
{
// this is the calculation
double result =(exp (-(n/(R*C))));
double voltage = result*E;
cout << "the voltage at " << n << " seconds is " << voltage << " volts" << std::endl;
// this prints the text to data file
myfile << n << "," << voltage << std::endl; // we include the comma so that matlab can
// pick up the data as a comma delimeted text file
}
myfile.close();
cout << std::endl;
cout << std::endl;
cout << "Please load data.txt into Matlab to plot this data" << std::endl;
return 0;
}
Open in new window