
package com.logicbig.example.math;
public class ExpExample {
public static void main(String... args) {
findExp(75.5);
findExp(-3);
findExp(0);
findExp(0.91);
}
private static void findExp(double x) {
double result = Math.exp(x);
System.out.printf("Math.exp(%S) = %s%n", x, result);
}
}
Output
Math.exp(75.5) = 6.155075488793534E32
Math.exp(-3.0) = 0.049787068367863944
Math.exp(0.0) = 1.0
Math.exp(0.91) = 2.4843225333848165

package com.logicbig.example.math;
public class ExpGraph {
public static void main(String... args) {
for (double i = 0; i <= 4; i = i + 0.5) {
double exp = Math.exp(i);
boolean isInt = i == Math.floor(i);
System.out.print(isInt ? ((int) i) + "-|" : " |");
System.out.printf("%s* (%.1f)%n", " ".repeat((int) exp) , exp);
}
}
}
Output
0-| * (1.0)
| * (1.6)
1-| * (2.7)
| * (4.5)
2-| * (7.4)
| * (12.2)
3-| * (20.1)
| * (33.1)
4-| * (54.6)

package com.logicbig.example.math;
public class ExpExample2 {
public static void main(String... args) {
System.out.println("Prove that x == x ^ ln(x) == ln(e ^ x) ");
System.out.println("-----------");
eval(0.5);
eval(2.5);
eval(5.1);
eval(8.7);
}
public static void eval(double x) {
double lhs = Math.exp(Math.log(x));
double rhs = Math.log(Math.exp(x));
System.out.printf("x= e ^ ln(x)= ln(e ^ x) :: %s = %.1f = %.1f%n", x, lhs, rhs);
}
}
Output
Prove that x == x ^ ln(x) == ln(e ^ x)
-----------
x= e ^ ln(x)= ln(e ^ x) :: 0.5 = 0.5 = 0.5
x= e ^ ln(x)= ln(e ^ x) :: 2.5 = 2.5 = 2.5
x= e ^ ln(x)= ln(e ^ x) :: 5.1 = 5.1 = 5.1
x= e ^ ln(x)= ln(e ^ x) :: 8.7 = 8.7 = 8.7