How to solve this equation with two variables in one equation ?

60 次查看(过去 30 天)
A = 1;
B = 1;
for n=0.0:0.1:1.0
for c = 0.0:0.1:1.0
c0 = 1.13e-4;
w = -A*(c-c0)^2*(n^4-3*n^2+2*n)+B.*(c-1)^2*n^2;
end
end

采纳的回答

Adam Danz
Adam Danz 2019-8-20
编辑:Adam Danz 2019-8-20
Loop through index values rather than a vector of values.
Store each iteration in w(n,c) and pre-allocate w with NaNs.
A = 1;
B = 1;
c0 = 1.13e-4;
% Vectors to loop through
nVec=0.0:0.1:1.0;
cVec = 0.0:0.1:1.0;
w = nan(numel(nVec),numel(cVec)); %pre-allocate with NaNs
% Loop through each element of nVec
for n=1:numel(nVec)
% Loop through each element of cVec
for c = 1:numel(cVec)
w(n,c) = -A*(cVec(c)-c0)^2*(nVec(n)^4-3*nVec(n)^2+2*nVec(n))+B.*(cVec(c)-1)^2*nVec(n)^2;
end
end
w(n,c) is the result for inputs nVec(n) and cVec(c)
  6 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by