MATLAB: Find optimum value to fit with the answer

for loopMATLAB

Hi all,
I would like to know how to find an optimium value to reach or fit with the final result even if I change other variables as shown:
clear all;
clc;
x=10; y=20;
k=x+y;
f=20; m=10;
t=1; % I need to find the optimum value of t which should be in this case 41
final=k+f+m+t
if final<100
disp('ok')
else
disp('no')
end

Best Answer

  • Can it be like this, if you want to find value if final>100
    clc;clear;
    syms x y t k f m
    x=10; y=20;
    k=x+y;
    f=20; m=10;
    final=k+f+m+t>=100
    t=solve(final,t)
    of if you want to find value if final=100
    clc;clear;
    syms x y t k f m
    x=10; y=20;
    k=x+y;
    f=20; m=10;
    final=k+f+m+t==100
    t=solve(final,t)