フィルターのクリア

Storage of a loop from negative number

2 ビュー (過去 30 日間)
Rafael Freire
Rafael Freire 2011 年 10 月 19 日
How i can storage a loop from negative number For example I have the below loop
for x=-1.5:0.01:1.5
for y=-1.5:0.01:1.5
(x,y)=92.5+(32.53333333)*(x)+(40.12702079)*(y)+(-42.2)*(x^2)+(-34.93538288)*(y^2)+(-3.464203233)*((x)*(y))
end
end
Best regards

採用された回答

Walter Roberson
Walter Roberson 2011 年 10 月 19 日
xvals=-1.5:0.01:1.5;
yvals=-1.5:0.01:1.5;
for J = 1:length(xvals)
for K = 1:length(yvals)
F(J,K)=92.5+(32.53333333)*(xvals(J))+(40.12702079)*(yvals(K)+(-42.2)*(xvals(J)^2)+(-34.93538288)*(yvals(K)^2)+(-3.464203233)*((xvals(J))*(yvals(K)))
end
end
This can be greatly simplified as:
F = bsxfun(@(x,y) 92.5+(32.53333333)*.(x)+(40.12702079).*(y)+(-42.2).*(x.^2)+(-34.93538288).*(y.^2)+(-3.464203233).*((x).*(y)), (-1.5:0.01:1.5).', -1.5:0.01:1.5);

その他の回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2011 年 10 月 19 日
i1 = -1.5:0.01:1.5;
f = @(x,y)92.5+32.53333333*x+40.12702079*y-42.2*x.^2-34.93538288*y.^2-3.464203233*x.*y;
Z = bsxfun(f,i1',i1);
  1 件のコメント
Oleg Komarov
Oleg Komarov 2011 年 10 月 19 日
Good Idea.

サインインしてコメントする。


Oleg Komarov
Oleg Komarov 2011 年 10 月 19 日
Loop version:
z = zeros(1,301^2);
n = 0;
for x =-1.5:0.01:1.5
for y =-1.5:0.01:1.5
n = n+1;
z(n)=92.5+32.53333333*x+40.12702079*y-42.2*x^2-34.93538288*y^2-3.464203233*x*y;
end
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by