Ettore Messina’s
Tech Blog

ChatGPT 4 Solving Ordinary Differential Equations

ChatGPT 4 Solving Ordinary Differential Equations - ettoremessina.tech

I submitted to ChatGPT 4 several ordinary differential equations with different levels of complexity and always ChatGPT 4 proposed correct solutions. But with an equation ChatGPT 4 found some difficulties: the first time it told me that there was no analytical solution, the second time it provided me with a blatantly wrong solution, the third time it gave me the correct solution.

The equation is:

\(y’ = e^{x – y} \)

The right solution is:

\(y(x) = log(c_1 + e^x) \)

you can see this is the solution using Wolfram Alpha following this link: https://www.wolframalpha.com/input?i=y%27+%3D+e%5E%28x-y%29

First attempt

My prompt was:

Solve this following ordinary differential equation: y’ = e^(x-y)

First of all there was an interesting thing: ChatGPT 4 showed an error (namely “Error analyzing”) and the following answer:

Solving the first-order differential equation \(y’ = e^{x – y} \) appears to be challenging due to its complexity, and the process has exceeded the time limit for computation. This type of equation is nonlinear and does not have a straightforward analytical solution. In practice, such equations are often approached through numerical methods, especially if specific initial conditions are given. If you have particular initial conditions or if a numerical approximation would be useful, please let me know, and I can assist with that approach.

On the error “Error analyzing” there was a linkable element that showed the underlying python code generated by ChatGPT 4 to solve the equation. This is the code:

# Redefine the first-order differential equation y' = e^(x - y)
first_order_differential_equation = Eq(y.diff(x), exp(x - y))

# Solve the first-order differential equation
first_order_solution = dsolve(first_order_differential_equation)
first_order_solution

Second attempt

After that answer I typed this prompt:

Think step by step

and ChatGPT 4 answered:

Certainly! Let’s solve the first-order differential equation \(y’ = e^{x – y} \) step by step:

1. Rearrange the Equation:
  • Start with \(y’ = e^{x – y} \).
2. Separate Variables:
  • To solve this equation, we aim to separate the variables \(y \) and \(x \). This means getting all \(y \) terms on one side of the equation and all \(x \) terms on the other.
  • We can rewrite the equation as \(e^y \, dy = e^x \, dx \)
3. Integrate Both Sides:
  • Next, integrate both sides of the equation. The integral of \(e^y \, dy \) is \(\int e^y \, dy = e^y \), and the integral of \(e^x \, dx \) is \(\int e^x \, dx = e^x \).
  • After integration, we get \(e^y = e^x + C \), where C is the constant of integration.
4. Solve for \(y \):
  • Finally, solve for \(y \) by taking the natural logarithm of both sides to get \(y = x + \ln(C) \), where \(\ln(C) \) represents an arbitrary constant.
So, the solution to the differential equation \(y’ = e^{x – y} \) is \(y = x + \ln(C) \), where C is an arbitrary constant. This solution assumes that C is positive, as the logarithm of a non-positive number is undefined.

The proposed solution is obviously wrong.

THIRD attempt

So I invited ChatGPT 4 to review the steps with this prompt:

Are you sure? I think your proposed solution is wrong. Check again the steps.

and ChatGPT 4 answered:

You are correct to question that solution. Let’s revisit the steps to solve the first-order differential equation \(y’ = e^{x – y} \) more accurately:

1. Rearrange the Equation for Separable Form:
  • The given equation is \(y’ = e^{x – y} \).
  • To make it separable, we need to express it in the form \(f(y) \, dy = g(x) \, dx \).
  • We can rewrite the equation as \(e^y \, dy = e^x \, dx \).
2. Integrate Both Sides:
  • Integrate both sides of the equation.
  • The integral of \(e^y \, dy \) is \(\int e^y \, dy \), and the integral of \(e^x \, dx \) is \(\int e^x \, d \).
  • After integration, we have \(\int e^y \, dy = \int e^x \, dx \).
3. Solve the Integrals:
  • The integral \(\int e^y \, dy \) is \(e^y \) and the integral \(\int e^x \, dx \) is \(e^x \).
  • Thus, the equation becomes \(e^y = e^x + C \), where \(C \) is the constant of integration.
4. Solve for \(y \):
  • To solve for \(y \), we rearrange the equation: \(e^y = e^x + C \).
  • Taking the natural logarithm of both sides gives us \(y = \ln(e^x + C) \).
So, the correct solution to the differential equation \(y’ = e^{x – y} \) is \(y = \ln(e^x + C) \), where \(C \) is an arbitrary constant. This solution accounts for the nonlinear nature of the equation.

and this time the proposed solution is the right one.

Conclusion

The legitimate question is: can ChatGPT 4 solve mathematical problems? As we saw yes, it can solve them, and I before writing this place I proposed a dozen differential equations and ChatGPT 4 has always found the right solution at the first attempt. However, ChatGPT 4 is not designed to solve mathematical problems (as seen in this post that two wrong solutions were proposed before having the right one), so in my opinion, you should not blindly trust the result, but first ask ChatGPT 4 to explain the steps and check all the steps carefully.

In the next post we will show how to use the Wolfram Plugin for ChatGPT and then we will have the combination of two tools: ChatGPT 4 operates on the natural language part, Wolfram Alpha takes care of the mathematical problem solving part.

Related Reads

NablaVis is an interactive web-based educational application designed to help students visualize and understand fundamental theorems of vector calculus through interactive 3D scenes. The tool allows users to explore scalar and vector fields, manipulate paths and surfaces, and observe real-time numerical verification of the mathematical relationships.
Jan 02 2026
NablaVis: an interactive educational tool to visualize three applications of Stokes’ Theorem
Why Stokes’ Theorem Is More Than a Formula Stokes’ Theorem transcends mere mathematical formulae by elegantly connecting fundamental...
Wolfram Alpha Plugin for ChatGPT Solving Differential Equations - ettoremessina.tech
Dec 23 2023
Wolfram Alpha Plugin for ChatGPT: Solving Differential Equations

This post shows how ChatGPT 4 assisted by the plugin Wolfram Alpha can solve a mathematical problem in better way than ChatGPT 4 alone.