Effacer les filtres
Effacer les filtres

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

60 vues (au cours des 30 derniers jours)
Robert101
Robert101 le 19 Août 2019
Commenté : Adam Danz le 20 Août 2019
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

Réponse acceptée

Adam Danz
Adam Danz le 20 Août 2019
Modifié(e) : Adam Danz le 20 Août 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 commentaires
Robert101
Robert101 le 20 Août 2019
Thanks man. You are great
Adam Danz
Adam Danz le 20 Août 2019
Glad I could help and learn along with ya!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by