Optimization- problem based approach- parameter identification using function solve
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Venkatesh Madhukar Deshpande
il 14 Mar 2021
Commentato: Venkatesh Madhukar Deshpande
il 16 Mar 2021
My aim is obtain value of x such that function expr in the code is minimized. The error I am getting is Objective must be a scalar OptimizationExpression or a struct containing a scalar OptimizationExpression. I have referred this forum and read some relevant posts. However, I am not able to solve the issue and hence this post. If there is a better of doing like not using a for loop to increase efficiency, etc., what I am attempting to do, then please suggest. Here is my code
A = 332.8668;%constant value
B = 128.6184;%constant value
n = 0.4234;%constant value
epsdot = 0.0001;%constant value
s = table2array(ExpDataMatlab);%using import button in GUI I import the data (file attached) and convert it to double.Represents experimental values
sigmaexp = s(:,2);%represents stress observed experimentally
eps = s(:,1);%represents strain
epsdot1 = s(:,3);%represents strain rate
x = optimvar('x',1);
expr = optimexpr;
sigmanum = @(x)(A+B*(eps.^n))*(1+x*log(epsdot1/epsdot));%represents stress calculated numerically where matlab will keep changing x until "expr" is minimized
for i = 1:length(sigmaexp)
expr = @(x)((1/i)*sum(abs((sigmaexp-sigmanum)/sigmaexp))*100);
end
JCproblem = optimproblem;
JCproblem.Objective = expr;%this final line is where I get the error. Hence I have given my further code followed by %
%options = optimset('PlotFcns',@optimplotfval);
%init.x = 0.0098 %initial guess of x;
%[sol,fval,exitflag,output] = solve(JCproblem,init,options);
0 Commenti
Risposta accettata
Walter Roberson
il 14 Mar 2021
A = 332.8668;%constant value
B = 128.6184;%constant value
epsdot = 0.0001;%constant value
n = 0.4234;%constant value
All scalars
eps = s(:,1);%represents strain
That's a column vector
epsdot1 = s(:,3);%represents strain rate
Column
sigmanum = @(x)(A+B*(eps.^n))*(1+x*log(epsdot1/epsdot));%represents stress calculated numerically where matlab will keep changing x until "expr" is minimized
eps is column vector, and n is a scalar, so eps.^n is a column vector. B is scalar and scalar times column vector is column vector. A is scalar and scalar plus column vector is column vector. So (A+B*(eps.^n)) is column vector
epsdot1 is a column vector, epsdot is a scalar, so epsdo1/epsdot is a column vector. log of that is a column vector. I think x is intended to be a scalar and scalar times column vector is column vector.
We now have two column vectors * each other. That is a dimension mismatch. P*Q requires that size(P,2) == size(Q,1) but the second dimension of a column vector is 1 and the first dimension of a column vector is not (usually) 1, so you have a problem. You need to transpose one of them if you want (n x 1) * (n x 1)' -> n x n, or you want (n x 1)' * (n x 1) -> 1 x 1. Or you need to switch to the .* operator, which would give you a column vector.
for i = 1:length(sigmaexp)
expr = @(x)((1/i)*sum(abs((sigmaexp-sigmanum)/sigmaexp))*100);
sigmanum is a function handle, and you are subtracting the function handle from the column vector. You cannot use a function handle in arithmetic. The only things you can do with a function handle are store them, pass them, or invoke them -- which requires using () with any parameters inside the ()
If you were to use sigmanum(x) then as explored above, you seem to be expecting a vector output from that function. Column vector sigmaexp minus column vector sigmanum is potentially acceptable. But then you have the / operator with a column vector on the right hand side. That is a legal operation, which would give an n x n matrix where n = size(sigmaexp,1) . abs() of that would be n x n, sum() of that would be 1 x n. So expr would be a function handle that returned a 1 x n vector.
Each iteration of for i you overwrite expr with the exact same content. You might as well only do one iteration.
However... your optimization function is required to return a scalar, but this would return a row vector.
10 Commenti
Walter Roberson
il 15 Mar 2021
Above that line insert
which norm(sigmaexp-sigmanum(x))
and see what you get out. I get
/MATLAB/toolbox/optim/problemdef/+optim/+problemdef/@OptimizationExpression/norm.p % optim.problemdef.OptimizationExpression method
at least in R2021a.
You can potentially code
norm(sigmaexp-sigmanum(x))
as
sqrt((sigmaexp-sigmanum(x)).*conj(sigmaexp-sigmanum(x)))
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Linear Least Squares 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!