Find the max using PSO
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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일
0 개 추천
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.
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
