필터 지우기
필터 지우기

How can I define boundary conditions using lsqnonlin solver?

조회 수: 1 (최근 30일)
Rookie
Rookie 2014년 8월 4일
답변: Fernando 2014년 8월 4일
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!

채택된 답변

Fernando
Fernando 2014년 8월 4일
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!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by