Advertisement
makispaiktis

Optimization - lsqcurvefit

Nov 1st, 2022 (edited)
1,284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.18 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5. %% Data and plot
  6. t = [3.92 7.93 11.89 23.90 47.87 71.91 93.85 117.84];
  7. c = [0.163 0.679 0.679 0.388 0.183 0.125 0.086 0.0624];
  8. figure();
  9. plot(t, c, 'bo');
  10. xlabel('t');
  11. ylabel('c');
  12.  
  13.  
  14. %% Model and optimization problem
  15. model = @(b, t)  b(1)*exp(-b(4)*t) + b(2)*exp(-b(5)*t) + b(3)*exp(-b(6)*t);
  16. options = optimoptions('lsqcurvefit', 'OutputFcn', ...
  17.                        @curvefittingcurvefittingpoltIterates, 'Display', 'none');
  18. problem = createOptimProblem('lsqcurvefit', 'objective', model, ...
  19.                              'xdata', t, 'ydata', c, 'x0', ones(1, 6), ...
  20.                              'lb', [-10 -10 -10 0 0 0], ...
  21.                              'ub', [10 10 10 0.5 0.5 0.5], ...
  22.                              'options', options);
  23.                          
  24. b = lsqcurvefit(problem);
  25.  
  26.  
  27. %% Multistart
  28. ms = MultiStart;
  29. ms.Display = 'iter';
  30. tic;
  31. rng default;
  32. [b, fval, exitflag, output, solutions] = run(ms, problem, 50);
  33. serialTime = toc;
  34. curvefittingpoltIterates(solutions)
  35.  
  36.  
  37. %% Parallel Computing
  38. ms.useParallel = true;
  39. gcp;
  40. tic;
  41. rng default;
  42. run(ms, problem, 50);
  43. parallelTime = toc;
  44. speedUp = serialTime / parallelTime;
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement