Find the max using PSO
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
T = readtable('data1.xlsx') ;
T = table2array(T) ;
x = T(1,2:end); % coil length
y = T(2:end,1); % magnitude length
Z = T(2:end,2:end); % use fillmissing to fill NaNs
[X,Y] = meshgrid(x,y) ;
[xq,yq] = meshgrid(2:0.1:10); % grid interval 0.1
Zq = interp2(x,y,Z,xq,yq,'spline');
figure
AA = surf(xq,yq,Zq);
title('(spline,cubic,makima) Interpolation Using Finer Grid');
%%
% example
% if input (1, 1), in interpolation (2.0, 2.0)
% if input (23, 23) , in interpolation (42, 42)
% if input (81, 81) , in interpolation (10.0 , 10.0)
% Upper limit& Lower limit are 1~81
Zq(1,1)
Zq(23,23)
Zq(81,81)
I have interpolated the attached table with the above code. Now I want to find the max using PSO, but I don't know how.
採用された回答
Star Strider
2021 年 10 月 26 日
This is at least the second time (the first that I°m aware of is how to get maximum value of this code) you’ve asked the same question and still haven’t supplied the necessary information!
And still more continue to appear!
9 件のコメント
kyungdoo lee
2021 年 10 月 26 日
I made a big mistake because I didn't have time. I really enjoyed reading your previous reply. I'm really sorry.
Star Strider
2021 年 10 月 26 日
Finding the maximum in the region-of-interest is straightforward —
T = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/779268/data1.xlsx');
T = table2array(T) ;
x = T(1,2:end); % coil length
y = T(2:end,1); % magnitude length
Z = T(2:end,2:end); % use fillmissing to fill NaNs
[X,Y] = meshgrid(x,y) ;
[xq,yq] = meshgrid(2:0.1:10); % grid interval 0.1
Zq = interp2(x,y,Z,xq,yq,'spline');
Warning: Columns of data containing NaN values have been ignored during interpolation.
[r,c] = find(Zq == max(Zq(:)));
Check = [xq(c),yq(r),Zq(r,c), max(Zq(:))]
Check = 1×4
2.0000 4.3000 0.0079 0.0079
figure
AA = surf(xq,yq,Zq);
hold on
stem3(xq(c),yq(r),Zq(r,c), '^r', 'MarkerFaceColor','r')
hold off
text(xq(c),yq(r),Zq(r,c), sprintf('\\leftarrow (%.2f, %.2f, %.2f)',xq(c),yq(r),Zq(r,c)), 'Horiz','left', 'Vert','middle', 'FontSize',10, 'Color','r', 'Rotation',90)
title('(spline,cubic,makima) Interpolation Using Finer Grid');

%%
% example
% if input (1, 1), in interpolation (2.0, 2.0)
% if input (23, 23) , in interpolation (42, 42)
% if input (81, 81) , in interpolation (10.0 , 10.0)
% Upper limit& Lower limit are 1~81
Zq(1,1)
ans = 0.0070
Zq(23,23)
ans = 0.0073
Zq(81,81)
ans = 0.0058
Finding whatever the global maximum may be (that may be outside of the region-of-interest) requires knowing the function that created the ‘Zq’ data, so that it can be appropriately parameterised and then optimised.
.
kyungdoo lee
2021 年 10 月 26 日
編集済み: kyungdoo lee
2021 年 10 月 26 日
First of all, I'm sorry again
Is the above code finding the maximum value using PSO?
My ultimate goal is to use the PSO to find the magnet and coil lengths that give the maximum values from the attached table. I used interpolation to make it more accurate.
Star Strider
2021 年 10 月 26 日
No worries.
‘Is the above code finding the maximum value using PSO?’
No. It is finding the max using the max function because that is the most efficient method here.
It is not possible to use pso or any other optimisation function because the function that created the data in the file (that would be used as the objective function in the optimisation) is not provided.
There is simply no need to use any specific optimisation function here, since the data are provided instead, and the limits to the variables are fixed.
‘My ultimate goal is to use the PSO to find the magnet and coil lengths that give the maximum values from the attached table. I used interpolation to make it more accurate.’
If the function that created the data is available, optimising it for the maximum or minimum would be possible. Since the function is not provided, using an optimisation function on the data is not possible.
.
kyungdoo lee
2021 年 10 月 26 日
You mean i can't use PSO if i don't know the function?
If so, how can I create a function in that graph?
Star Strider
2021 年 10 月 26 日
‘You mean i can't use PSO if i don't know the function?’
Yes. (That also applies to every other optimsiation function.)
’If so, how can I create a function in that graph?’
I honestly do not know, because I have no idea what it is or what created it. If those are data, then it would likely (although not certainly) be possible to fit a function to it to estimate a subset of the parameters of the function, and then optimise it with respect to other parameters.
If the plotted surface are data, and fitting a function to it is the objective, then the function would need to be provided, and also clearly described with respect to the variables, other arguments (if necessary), and parameters. Then any appropriate oprimisation function could be used to estimate the parameters and fit the function to the data.
A call to the ‘Harmony’ function appeared in at least one post earlier, however I have no idea what it is or what it does because the code for it was never posted. It may (or may not) be the objective function required for the optimisation.
I have no way of knowing anything other than what was posted.
.
kyungdoo lee
2021 年 10 月 26 日
Thank you for the reply.
kyungdoo lee
2021 年 10 月 26 日
In the graph above, the Z-axis number is too small to display well. How can I get a more accurate z-value?
Star Strider
2021 年 10 月 26 日
As always, my pleasure!
The ‘Z’ value is as accurate as it needs to be. To increase the numbers displayed in the text object, increase the precision in the format specifying it —
text(xq(c),yq(r),Zq(r,c), sprintf('\\leftarrow (%.2f, %.2f, %.8f)',xq(c),yq(r),Zq(r,c)), 'Horiz','left', 'Vert','middle', 'FontSize',10, 'Color','r', 'Rotation',90)
To display it in its full precision, either use —
format long
or —
fprintf('Zq_max = %23.15E\n',Zq(r,c))
to print it in full precision. (The format functions apparently do not work with the online Run feature here, however they will work on your computer.)
.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Particle Swarm についてさらに検索
製品
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
