Why does my function abc give error with optimtool

I have a function file abc. I want to run it with optimtool ga. I do settings in the Optimtool as below:
Solver: ga-Genetic Algorithm
Fitness function: @abc
Number of variable 6
Bounds Lower: [0 0 0 0 0 0] Upper:[180 180 180 180 180 180]
-----------------------------
After running it, it gives the following error:
Optimization running.
Error running optimization.
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.

 採用された回答

Torsten
Torsten 2022 年 7 月 12 日

0 投票

The product r*k in the line
A = exp(-1j*r*k);% Steering matrix
is not defined.
k is (3x3), r is (Nx3) where N = 10.
Setting N = 3 would make the product to be defined.

6 件のコメント

Torsten
Torsten 2022 年 7 月 12 日
See above.
b must be of the same size as [az,el].
Torsten
Torsten 2022 年 7 月 12 日
And if you knew this, why did you ask what caused the error in your call of abc ?
Torsten
Torsten 2022 年 7 月 12 日
I asked that when the code is correct, then why does it give error with the optimtool?
Because the optimtool works with a (6x1) vector (as I see from the definition of your lower and upper bounds) whereas you need it reshaped as a (3x2) matrix for abc.
Torsten
Torsten 2022 年 7 月 14 日
編集済み: Torsten 2022 年 7 月 14 日
So what do you suggest?
I already wrote what you have to do.
Before calling abc, you have to reshape the vector b supplied by ga as
b = reshape(b,3,2)
Sadiq Akbar
Sadiq Akbar 2022 年 7 月 14 日
Thank you very much dear Torsten for your help. But now there is one issue. When I keep the bounds as:
Lower=[0;0;0;0;0;0] Upper=[360;360;360;180;180;180]
It gives wrong results. But when I change them to:
Lower=[0;0;0;0;0;0] Upper=[180;180;180;180;180;180]
then it gives good results. Although the actual range is the 1st case. So what do I do now?
Torsten
Torsten 2022 年 7 月 14 日
I have no experience with ga.
If your problem is such that you can use "fmincon" or some other deterministic optimizer instead of ga, you should do so.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProblem-Based Optimization Setup についてさらに検索

質問済み:

2022 年 7 月 12 日

編集済み:

2022 年 7 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by