Indexing inside a function

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);

 采纳的回答

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

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

产品

版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by