How can I determine (optimize) 4 constants or parameters for an equation with 4 variables in Matlab

Hello everyone, I have got an equation with 4 variables and 4 constants as shown below: Z=c * V^-m * P^n * S^x where Z, V, P and S are variables (known data) and c, m, n and x are constants (unknown). I want to find the 4 constants. Could you please help me for this issue?

Answers (1)

If you have no constraints (limits on your variables), use fminsearch. For an example of its use, see the documentation.
If there are constraints (such as some variables must be positive) and you have an Optimization Toolbox license, use fmincon.
Alan Weiss
MATLAB mathematical toolbox documentation

3 Comments

Hello Alan,
Many thanks for your response.
I tried below code,
after run the code it gives below
Function definitions are not permitted in this context.
how can I deal with this? I have limited experience in Matlab
clear; clc; close all;
% v p Sr Mv
Data=[
2.210023964 1.96632798 0.622109327 149.0547533
2.196296497 2.386462852 0.628820951 152.8242102
2.166753567 2.930816699 0.643605566 173.3434531
2.130513499 3.489837947 0.663279316 200.357107
2.093573729 4.058286535 0.686095512 224.3755318
2.051858223 4.642544991 0.714181664 253.672975
2.014818496 5.222616915 0.740872305 286.0343537
2.006311021 5.243873893 0.747957964 298.5776738
2.006544255 4.746250414 0.748750138 293.0350632
2.009465229 4.245741408 0.748580469 278.3670001
2.015040624 3.741874992 0.747291664 258.6910752
2.022992781 3.234267866 0.744755955 237.3993754
2.03478774 2.721358308 0.740452769 212.7082272
2.053013285 2.298431295 0.732810432 196.4847033
2.199857403 1.983437327 0.627812442 150.9624436
2.249930722 0.521817469 0.843634937 150.4423024
2.184999217 2.35849701 0.752832337 203.9696001
2.179784486 2.595391932 0.748463977 206.7854166
2.170807228 2.755011548 0.751670516 212.9453498
2.154370923 3.066462125 0.755487375 226.4062671
2.140453972 3.280966559 0.760322186 235.6738926
2.106921271 3.816402454 0.772134151 260.1511025
2.075137815 4.354842408 0.784947469 295.4490173
2.043596394 4.912870738 0.797623579 329.9586459
2.014981382 5.433358856 0.811119619 354.5100443
2.006169147 5.445896105 0.815298702 375.4243071
];
V=Data(:,1); % v
P=Data(:,2); %p*
S=Data(:,3); %Sr
M=Data(:,4); %Mv
function b = four_var(v)
V = v(1);
P = v(2);
S = v(3);
M = v(4);
b = c * V^m * P^n * S^x
%Now find a minimum for this function using V = 1.947
% P = 0.5127, S= 0.6105 and M = 142.534 as the starting values.
v = [1.947 0.5127 0.6105 142.534];
a = fminsearch(@three_var,v)
??
You have V, P, S, M in your matrix, but you said that m is a constant to be found. You do not have Z in your matrix but you said Z was known. Your function uses c without defining it.

Sign in to comment.

Tags

Asked:

on 3 Dec 2015

Commented:

on 3 Dec 2015

Community Treasure Hunt

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

Start Hunting!