CrazyEngineers
  • MATLAB Question - Optimization

    ebahous

    ebahous

    @ebahous-neOS1p
    Updated: Oct 22, 2024
    Views: 1.4K
    Hello,

    I am an ME STudent currently trying to solve a project with MATLAB.

    First of all let me introduce the problem. I just solved a Differential Equation that gives me a vector of Temperatures. As inputs I had a vector of power, air temperature and thermal resistance.

    So out of this code I got a calculated temperatur.

    I also did measurements on an engine and I got a vector of temperature that I will call measured temperatures.

    Now I want to minimize the error between the measured temperatur and the calculated temperature with MATLAB in order to find the best suited Thermal resistance at each point.

    Here is my code...it never stops thats the problem

    function rest = versuch_optim_2(x,temp,t,y1,f,g,ft,gt)

    rest = 0;

    f = interp1(ft,f,t,
    'linear','extrap')'; % Interpolate the data set (ft,f) at time t (linear Method), extrapolate if t is outside of ft
    g = interp1(gt,g,t,'linear','extrap')'; % Interpolate the data set (gt,g) at time t (linear Method), extrapolate if t is outside of gt



    for i = 1:length(t)

    dydt = (f(i)/(800*480) - ((temp(i)-g(i))./(x * 800 *480))) - y1(i);
    % Evalute ODE at time t

    rest = rest + dydt(1).^2;

    end

    ________________________________________________________

    and I use the following script line to call my code...does anyone know how to solve this...and am I posting this in the wrong place?

    [x val]= fminsearch(@(x) versuch_optim_2(x,temp,t,y1,f,g,ft,gt), [1;(1:length(t))'],optimset('MaxFunEvals',10000,'MaxIter',10000))

    Thank you

    Edouard
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Home Channels Search Login Register