/*
#include <LiquidCrystal.h>
#include <math.h>
// Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
double calculateY(double x) {
if (x == 0.5) {
return NAN; // Explicitly return NaN if x = 0.5 to handle the division by zero case
}
double sineValue = sin(x - 0.5);
if (sineValue == 0) {
return NAN; // Additional safety check for sine value being zero
}
double term1 = 56 * (pow(x, 3) / sineValue);
double term2 = sqrt(1 / x);
return term1 - term2;
}
void setup() {
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
Serial.begin(9600); // Initialize serial communication at 9600 bps
// Display the initial information on the LCD
lcd.setCursor(0, 0);
lcd.print("y=56*(x^3/sin(");
delay(2000); // Wait for 2 seconds
lcd.setCursor(0, 1);
lcd.print("x-0.5))-sqrt(1/x)");
delay(3000); // Wait for 3 seconds
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Range: 0.1-0.6");
lcd.setCursor(0, 1);
lcd.print("Step: 0.05");
delay(3000); // Wait for 3 seconds
double x;
double step = 0.05;
double minX = 0.1;
double maxX = 0.6;
double y;
double maxY = -INFINITY;
double minY = INFINITY;
double maxY_x = 0;
double minY_x = 0;
for (x = minX; x <= maxX; x += step) {
y = calculateY(x);
lcd.clear();
if (isnan(y)) {
lcd.setCursor(0, 0);
lcd.print("x=");
lcd.print(x, 5); // Print x with 2 decimal places
lcd.setCursor(0, 1);
lcd.print("y=undefined");
} else {
lcd.setCursor(0, 0);
lcd.print("x=");
lcd.print(x, 2); // Print x with 2 decimal places
lcd.setCursor(0, 1);
lcd.print("y=");
lcd.print(y, 2); // Print y with 2 decimal places
// Update max and min y values
if (y > maxY) {
maxY = y;
maxY_x = x;
}
if (y < minY) {
minY = y;
minY_x = x;
}
}
delay(3000); // Wait for 3 seconds before showing the next value
}
// Display maximum y value
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Max y=");
lcd.print(maxY, 2);
lcd.setCursor(0, 1);
lcd.print("at x=");
lcd.print(maxY_x, 2);
delay(5000); // Wait for 5 seconds
// Display minimum y value
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Min y=");
lcd.print(minY, 2);
lcd.setCursor(0, 1);
lcd.print("at x=");
lcd.print(minY_x, 2);
delay(5000); // Wait for 5 seconds
}
void loop() {
// Nothing to do here
}
*/