How to prevent complex solutions from lsqnonlin

1 回表示 (過去 30 日間)
Kai Chung
Kai Chung 2015 年 8 月 18 日
回答済み: Walter Roberson 2015 年 8 月 18 日
I am trying to determine the parameter of an equation using lsqnonlin.
y = x.^a
Where x and y are input and output data, and a is the parameter to be solved for.
This is the part of my code:
Y_fn = @(apara) ((X_meas).^(apara(1))-Y_meas);
apara = lsqnonlin(Y_fn,init,LB,UB,Y_meas);
Running the script yields solutions for a such as -0.1771 + 1.1983i. How do I prevent obtaining complex solutions?
Thanks

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 8 月 18 日
If any of your X_meas are negative then you are likely to get complex results unless you use a lower bound of 0 for apara. A negative value raised to a non-integral exponent using .^ is going to return a complex value.

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by