How to minimize a parameter in a differential equation

3 次查看(过去 30 天)
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?

采纳的回答

Mohammad Abouali
Mohammad Abouali 2015-4-2
编辑:Mohammad Abouali 2015-4-2
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 个评论
Mohammad Abouali
Mohammad Abouali 2015-4-2
Regarding your email question:
Passing objectiveFunction to minimizing function means something like this:
fminsearch(@objectiveFunction,initCond)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Polymers 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by