How to minimize a parameter in a differential equation

3 views (last 30 days)
I have this MATLAB code for solving the heat equation using Explicit Euler Method
if true
% L = 1.;
T =1.;
maxk = 2500;
dt = T/maxk;
n = 50;
dx = L/n;
cond = 1/4; %%%%%%%%%%Conductivity parameter
b = 2.*cond*dt/(dx*dx);
for i = 1:n+1
x(i) =(i-1)*dx;
u(i,1) =sin(pi*x(i));
end;
for k=1:maxk+1
u(1,k) = 0.;
u(n+1,k) = 0.;
time(k) = (k-1)*dt;
end;
for k=1:maxk
for i=2:n;
u(i,k+1) =u(i,k) + 0.5*b*(u(i-1,k)+u(i+1,k)-2.*u(i,k));
end;
end;
end
I am given the actual solution and I am asked to interpolate the numerical solution data to match the actual data intervals. Then I have to minimize the square error function of the difference between the actual and the numerical data with respect to Conductivity (cond) using free-derivative optimization method such as Nelder-Mead method.
I know how to interpolate as well as minimize using these methods but with an objective function and variables.
In my case, the objective function is just data and it doesn't have the conductivity paramter. It is inside the numerical solution code.
How the minimization is done in this case?

Accepted Answer

Mohammad Abouali
Mohammad Abouali on 2 Apr 2015
Edited: Mohammad Abouali on 2 Apr 2015
Here is the outline of the code for objective function
objectiveFunction (Conductivity)
-- Use the above code you mentioned and get an estimate for U
-- compare that U with the actual U that you have (calculate the differences)
-- (possibly) reduce the difference into one number such as RMSE or MSE or whatever measure that you like
end of objectiveFunction
Now pass the objectiveFunction to your minimizing function let's say fminsearch (since you mentioned you want to use nelder-mead. That way it changes cond until it gets the best match for numerical solution and the actual solution.
Pretty much you need to run the above code many times. Make sure the cond is not hard coded in the solver part. You can make the code more flexible if you want like having variable domain size or solution etc. start with the simplest.
  1 Comment
Mohammad Abouali
Mohammad Abouali on 2 Apr 2015
Regarding your email question:
Passing objectiveFunction to minimizing function means something like this:
fminsearch(@objectiveFunction,initCond)

Sign in to comment.

More Answers (0)

Categories

Find more on Polymers in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!