Azzera filtri
Azzera filtri

How can I define boundary conditions using lsqnonlin solver?

1 visualizzazione (ultimi 30 giorni)
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!

Risposta accettata

Fernando
Fernando il 4 Ago 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!

Più risposte (0)

Categorie

Scopri di più su Operating on Diagonal Matrices 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!

Translated by