Evaluating a function with three variables
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alin Brad
am 26 Sep. 2018
Kommentiert: Walter Roberson
am 28 Sep. 2018
Dear all, Since I am new in MatLab, I want to evaluate the following equation y=(1./((x.^2)+1))-(p./((x+w).^2+1))-(p./((x-w).^2+1)); I want to sweep the variables x,p and w as follows x from -5 to 5 with 100 steps ,p from 0 to 1 with 100 steps ,w from 0 to 3 with 100 steps and then I want to normalized the functiony and then I want to extract the specific values of x (lets name new variable r) which give me specific value of y (lets say y=0.5) for each combination of variables x,w,p. After that I want to make a surface graph of ( r,w and p)
thanks
1 Kommentar
Akzeptierte Antwort
KSSV
am 26 Sep. 2018
Bearbeitet: KSSV
am 26 Sep. 2018
N = 100 ;
x = linspace(-5,5,N) ;
p = linspace(0,1,N) ;
w = linspace(0,3,N) ;
[x,p,w] = meshgrid(x,p,w) ;
y=(1./((x.^2)+1))-(p./((x+w).^2+1))-(p./((x-w).^2+1));
figure
hold on
for i = 1:N
surf(x(:,:,i),p(:,:,i),w(:,:,i),y(:,:,i))
end
% GEt manually y = 0.5
idx = abs(y-0.5)<=10^-3 ;
xr = x(idx) ;
pr = p(idx) ;
wr = w(idx) ;
figure
scatter3(xr,pr,wr,10,wr)
% use isosurface
p = patch(isosurface(x,p,w,y,0.5));
p.FaceColor = 'red';
p.EdgeColor = 'none';
daspect([1 1 1])
view(3);
axis tight
camlight
lighting gouraud
6 Kommentare
Walter Roberson
am 26 Sep. 2018
You would not use val as idx. You would use
idx = abs(y-val)<=10^-3 ;
Weitere Antworten (1)
Alin Brad
am 26 Sep. 2018
4 Kommentare
Walter Roberson
am 28 Sep. 2018
Notice in my call I did not select subsets of x and so on for the isosurface call: I left them the original size but assigned nan to locations in the grid that were not of interest.
Siehe auch
Kategorien
Mehr zu Volume Visualization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!