Filter löschen
Filter löschen

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

60 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Adam Danz
Adam Danz am 20 Aug. 2019
Bearbeitet: Adam Danz am 20 Aug. 2019
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 Kommentare
Robert101
Robert101 am 20 Aug. 2019
Thanks man. You are great
Adam Danz
Adam Danz am 20 Aug. 2019
Glad I could help and learn along with ya!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Contour Plots 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!

Translated by