필터 지우기
필터 지우기

Evaluate Function at different data points from vectors

조회 수: 9 (최근 30일)
Jalal Hassan
Jalal Hassan 2020년 6월 28일
댓글: Joseph Moore 2022년 6월 9일
I have three vectors
x = [ 0.05 0.06 ]
y = [ 1.23 1.41 ]
z = [ 0.1 0.2]
Now I want to evaluate function at all values such as
f(0.05,1.23,0.1)=2.6629
f(0.05,1.23,0.2)=2.7629
f(0.05,1.41,0.1)=3.1381
f(0.05,1.41,0.2)=3.2381
f(0.06,1.23,0.1)=2.6729
f(0.06,1.23,0.2)=2.7729
f(0.06,1.41,0.1)=3.1481
f(0.06,1.41,0.2)=3.2481
These values should be saved in a vector.

채택된 답변

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020년 6월 28일
편집: Thiago Henrique Gomes Lobato 2020년 6월 28일
Use meshgrid to generate all combinations and make your function accept vector entries. Ex:
f = @(x,y,z)x.*y+z; % Insert your function
x = [ 0.05 0.06 ];
y = [ 1.23 1.41 ];
z = [ 0.1 0.2];
[XX,YY,ZZ] = meshgrid(x,y,z); % Create all possible combinations
w = f(XX(1:end),YY(1:end),ZZ(1:end))
w =
0.1615 0.1705 0.1738 0.1846 0.2615 0.2705 0.2738 0.2846
  댓글 수: 2
Jalal Hassan
Jalal Hassan 2020년 6월 30일
Can I have these in a following order because I need to use these values in a formula.
Order should be like this
x = [x1 x2]
y = [y1 y2]
z = [z1 z2]
f(x1,y1,z1)
f(x1,y1,z2)
f(x1,y2,z1)
f(x1,y2,z2)
f(x2,y1,z1)
f(x2,y1,z2)
f(x2,y2,z1)
f(x2,y2,z2)
Q = [ f(x1,y1,z1) f(x1,y1,z2) f(x1,y2,z1) f(x1,y2,z2) f(x2,y1,z1) f(x2,y1,z2) f(x2,y2,z1) f(x2,y2,z2)]
Joseph Moore
Joseph Moore 2022년 6월 9일
and I want them on my desk by moday

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Smoothing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by