Assigment 4
Assigment 4
h>
#include <stdlib.h>
#include <math.h>
typedef struct {
double time; // Time
double voltage; // Voltage
double current; // Current
} Measurement;
*num_measurements = 0;
while (fscanf(file, "%lf %lf %lf", &measurements[*num_measurements].time,
&measurements[*num_measurements].voltage,
&measurements[*num_measurements].current) == 3) {
(*num_measurements)++;
}
fclose(file);
}
void write_results(const char *filename, double *data1, double *data2, int count,
int increment) {
FILE *file = fopen(filename, "w");
if (!file) {
perror("Failed to open file for writing");
exit(EXIT_FAILURE);
}
fclose(file);
}
fclose(file);
}
int main() {
Measurement measurements[MAX_DATA_POINTS];
int num_measurements;
// Load data
read_data("PZT.txt", measurements, &num_measurements);
// Constants
double density_PZT = 8000; // kg/m^3
double dia_PZT = 6e-3; // m
double h_PZT = 5.5e-3; // m
double area_PZT = PI * (dia_PZT / 2.0) * (dia_PZT / 2.0); // m^2
// Calculations
for (int i = 0; i < num_measurements; i++) {
power[i] = measurements[i].voltage * measurements[i].current; // Power in W
return 0;
}