The problem i am having is i want to use fminsearch for a fuction containing every value inside my two matrixes. As i am creating a saturation line for pressure. and want it to minimize the distance between my measured Temperatures and Pressures. Basicly reduce f1-f5 to one function that i can use a singe fminsearch on. Thanks in advance!
A = 10.493056201500981;
B = 1.663772278341260e+03;
x = [A,B];
Temperature = [101.5245 106.0325 107.8912 110.6541 114.8397];
Pressure = [106.0448 122.4084 132.3047 146.6630 172.5796];
f1 = @(x) sum(abs(Pressure(1)-(1/10000)*10^(x(1)-x(2)/(273+Temperature(1)))));
f2 = @(x) sum(abs(Pressure(2)-(1/10000)*10^(x(1)-x(2)/(273+Temperature(2)))));
f3 = @(x) sum(abs(Pressure(3)-(1/10000)*10^(x(1)-x(2)/(273+Temperature(3)))));
f4 = @(x) sum(abs(Pressure(4)-(1/10000)*10^(x(1)-x(2)/(273+Temperature(4)))));
f5 = @(x) sum(abs(Pressure(5)-(1/10000)*10^(x(1)-x(2)/(273+Temperature(5)))));
Optimalisering1 = fminsearch(f1,x);
Optimalisering2 = fminsearch(f2,x);
Optimalisering3 = fminsearch(f3,x);
Optimalisering4 = fminsearch(f4,x);
Optimalisering5 = fminsearch(f5,x);

 Accepted Answer

Matt J
Matt J on 21 Apr 2022
Edited: Matt J on 21 Apr 2022
This might be what you want,
A = 10.493056201500981;
B = 1.663772278341260e+03;
x0 = [A,B];
TemperatureKelvin = 273+[101.5245 106.0325 107.8912 110.6541 114.8397];
Pressure = [106.0448 122.4084 132.3047 146.6630 172.5796];
f= @(x) norm( Pressure-10.^( x(1)-4-x(2)./TemperatureKelvin ) ,1) ;
[Optimalisering,fopt] = fminsearch(f,x0)
Optimalisering = 1×2
1.0e+03 * 0.0126 2.4537
fopt = 4.3992

More Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!