How can I define boundary conditions using lsqnonlin solver?

2 Ansichten (letzte 30 Tage)
Rookie
Rookie am 4 Aug. 2014
Beantwortet: Fernando am 4 Aug. 2014
Hi everyone,
I am trying to solve an equation: K * u = q(u)
where q is a function of u. For this reason I formed an error-loading vector: qerr(u) = K * u - q(u)
I am using a lsqnonlin solver. I am trying to implement boundary conditions by setting certain elements of u vector to 0.
I scanned the mathworks but I cannot find a solution to this problem.
Thank you for your help!

Akzeptierte Antwort

Fernando
Fernando am 4 Aug. 2014
First I'd suggest you to create an m-file to evaluate your error vector.
% Example for that function:
function Error = CostFunction(Unknowns)
% Unknowns can be a vector, so you can extract it like this:
a = Unknowns(1);
b = Unknowns(2);
% Compute the Error here.
% End of m-file
Now in your main m-file you can define the initial conditions for your unknowns:
Unknowns = [1, 0, 4]; % 3 variables in this example
options = optimset(' .... ', ' .... '); % your solver options goes here
UnknownsLB = [0, -5, 2]; % lower bound definition
UnknownsUB = [2, 5, 10]; % upper bound definition
x = lsqnonlin(@CostFunction,Unknowns,UnknownsLB,UnknownsUB,options) % solve it!

Weitere Antworten (0)

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by