Borrar filtros
Borrar filtros

How can I define boundary conditions using lsqnonlin solver?

1 visualización (últimos 30 días)
Rookie
Rookie el 4 de Ag. de 2014
Respondida: Fernando el 4 de Ag. de 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!

Respuesta aceptada

Fernando
Fernando el 4 de Ag. de 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!

Más respuestas (0)

Categorías

Más información sobre Operating on Diagonal Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by