Which approach is useful here to get a plot?

1 view (last 30 days)
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?

Accepted Answer

KSSV
KSSV on 1 Dec 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 Comments
KSSV
KSSV on 1 Dec 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 on 2 Dec 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!