Effacer les filtres
Effacer les filtres

How can I define boundary conditions using lsqnonlin solver?

1 vue (au cours des 30 derniers jours)
Rookie
Rookie le 4 Août 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!

Réponse acceptée

Fernando
Fernando le 4 Août 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!

Plus de réponses (0)

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by