Which approach is useful here to get a plot?

1 vue (au cours des 30 derniers jours)
Trim Dim
Trim Dim le 1 Déc 2022
Commenté : Trim Dim le 2 Déc 2022
I have this function with two input parameters
I'm used to graphing functions with a single parameter.
But how can you get an output with two parameters?
How will it be passed to the function if I create two arrays
for each input parameter? I'd want to have input in the
range [0,1]. Is there another example?

Réponse acceptée

KSSV
KSSV le 1 Déc 2022
Check and then use. I have quickly typed it without much thought.
n1 = linspace(0,1) ;
n2 = linspace(0,1) ;
n = cat(3,n1,n2) ;
% First summation
T1 = zeros(size(n1)) ;
for i = 1:2
T1 = T1 + -1/2*n(:,:,i)+1/4*n(:,:,i).^4 ;
end
% Second summation
for i = 1:2
T2 = n(:,:,i).^2 ;
for j = 1:2
if j ~= i
T2 = T2.*n(:,:,j).^2 ;
end
end
end
iwant = T1+T2 ;
  3 commentaires
KSSV
KSSV le 1 Déc 2022
Perfect..
n1 = linspace(0,1) ;
n2 = linspace(0,1) ;
[n1,n2] = meshgrid(n1,n2) ;
n = cat(3,n1,n2) ;
% First summation
T1 = zeros(size(n1)) ;
for i = 1:2
T1 = T1 + -1/2*n(:,:,i)+1/4*n(:,:,i).^4 ;
end
% Second summation
for i = 1:2
T2 = n(:,:,i).^2 ;
for j = 1:2
if j ~= i
T2 = T2.*n(:,:,j).^2 ;
end
end
end
iwant = T1+T2 ;
surf(n1,n2,iwant)
Trim Dim
Trim Dim le 2 Déc 2022
Although the output is very similar but in the expected output
(as in my attachment) there is a bump in the center
and the edges show minima at n1=1 and n1=0 and also at
n2=1 and n2=0.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by