Minimum of bivariable function
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi everyone,
I just started using MATLAB and I'm trying to find the minmum of a bivariable function (CT(T1, T2)) and the correspoding 2D plot. Below the code used:
clear all ; clc ;
syms x;
syms T1;
syms T2;
H1=50;
%T2=10;
%T1=11;
Mp1=400;
Mc1=1500;
Mp2= 442.0684;
Mc2=1700;
H=100;
H2=H-H1;
w=0.1;
F1=@(T1)1-exp(-((T1-x)./100)).^2;
F2=@(T2) 1-exp(-((T2-x)./100)).^1.8;
f1=@(T1) 1-exp(-((H1-floor(H1./T1).*T1)-x)./100).^2;
f2=@(T2) 1-exp(-((H2-floor(H2./T2).*T2)-x)./100).^1.8;
A=@(T1)((H1./T1).*((-log(1-int(((30).*exp(-30).*x)*((1-exp(-((T1-x)./100)).^2)),0,T1)).*Mc1+(Mp1))))./H1;
B=@(T1)(-log(1-int((F1*((30).*exp(-30).*x)),0,(H1-(floor(H1./T1)).*T1)).*Mc1)./H1);
C=Mp2./H1;
D=@(T2)((H2./T2).*((-log(1-int(((1-exp(-((T2-x)./100)).^1.8))*((25).*exp(-25).*x),0,T2))).*(Mp1.*exp(w))))./H2;
E=@(T2)((-log(1-int((1-exp(-((H2-((H2./T2)).*T2)-x)./100))*((25).*exp(-25).*x),0,(H2-((H2./T2))).*T2))))*(Mc1.*exp(w))./H2;
CT=@(T1,T2)(A(T1)+B(T1)+C+D(T2)+E(T2))
Thanks.
0 Commenti
Risposte (1)
Shishir Reddy
il 8 Gen 2025
Hi Jean
Below are the key changes and code snippets that can be added to your existing MATLAB code to find the minimum and plot the 2D function.
1. Optimization using fmincon: An optimization problem needs to be set up, to find the minimum of CT(T1, T2). This can be done as follows -
% Initial guess
T0 = [10, 10];
lb = [1, 1];
ub = [100, 100];
options = optimoptions('fmincon', 'Display', 'iter');
[T_opt, CT_min] = fmincon(@(T) CT(T(1), T(2)), T0, [], [], [], [], lb, ub, [], options);
disp(['Optimal T1: ', num2str(T_opt(1))]);
disp(['Optimal T2: ', num2str(T_opt(2))]);
disp(['Minimum CT: ', num2str(CT_min)]);
2. 2D Plotting using meshgrid and surf: To visualize the function CT(T1, T2), a grid of T1 and T2 values has to be vreated and CT can be evaluated over this grid.
[T1_grid, T2_grid] = meshgrid(1:0.5:100, 1:0.5:100);
CT_grid = arrayfun(CT, T1_grid, T2_grid);
figure;
surf(T1_grid, T2_grid, CT_grid);
xlabel('T1');
ylabel('T2');
zlabel('CT');
title('2D Plot of CT(T1, T2)');
These snippets can be integrated with the existing code to perform the optimization and visualization tasks.
For more information regarding the optimoptions and surf functions, kindly refer the following documentations -
I hope this helps.
0 Commenti
Vedere anche
Categorie
Scopri di più su Calculus in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!