evaluate multiple variables with matlab code, (relooping?)

7 vues (au cours des 30 derniers jours)
kwadwo
kwadwo le 20 Déc 2012
Hey all, Im trying to evaluate an equation with multiple variables,4, whereby 2 are known and 2 are unknown.
so the equation is f=(c/(2*pi))*sqrt(A/(Vl))
f and A are known V and l are unknown
%
A=0.001019;
c = 343;
V= 0.001:0.0001:0.020;
i=0;
l=0.1:0.001:0.6;
j=0;
fmax=58.7;
f=0;
fwanted = 58.7
(%code----)
for i=1:length(V)
for j=1:length(l)
f = (c/(2*pi))*sqrt((A)/(V(i)*l(j)));
if fwanted ==f
V(i)
l(j)
end
end
end
With the code above i only get one solution. I actually want to code to run like this: take the first element of V, keep it constant and run the function with the columns of l. take the second element of V and run it again and so on and display the solutions at the end. whereby creating multiple combinations of V and l. since my knowlegde is limited on this. can anybody help?

Réponse acceptée

Walter Roberson
Walter Roberson le 20 Déc 2012
  8 commentaires
kwadwo
kwadwo le 27 Déc 2012
Modifié(e) : kwadwo le 27 Déc 2012
Hey Roger, I know this method is not efficient, also because of the approximation. what way do u then suggest i use, because i m struggling to find the solutions to an extended equation of the one here above, with more unknown variables, but with a given range. which is presented in the code below. The equation can not be transformed to an equation with all unkowns on one side of the equation. that is why i was trying it out for a less difficult equation. or did I misunderstand u? additionally, matlab seems to get stuck in running the program and does not present any solutions. I have read it is due to the performance of matlab (taking too long)? do u perhaps have a solution for this. the equation in the code is absolutely correct. Walter your input in this would also be highly appriciated.
% code
clc
tic
c = 340.3;
Fn=0.001019;
ln=0.46:0.001:0.8;
Vn=0.00046874:0.00001:0.00081520;
V= 0.003:0.0001:0.008;
h=0.001:0.0001:0.3400;
r=sqrt(Fn/pi);
l01=0.24*r;
l02=0.24*r;
V01=Fn*l01;
lv=0.0002;
i=0;
l=0;
k=0;
u=0;
s=0;
t=0;
fwanted = 58.4;
Vl=[];
for i=1:length(V)
for j=1:length(ln);
for k=1:length(h)
for u=1:length(Vn);
f = (c/(2*pi))*sqrt(Fn/((1.21*(V(i)+Vn(u)))*(((V(i)/(V(i)*Vn(u)+V01)))*... (lv+((ln(j)+l01)*(1+0.5*(((Vn(u)+V01)/V(i))+((ln(j)+l01)/h(k)))+((1/3)*...((Vn(u)+V01)/V(i))*((ln(j)+l01)/h(k))))))+l02)));
if abs(fwanted-f) < 0.01
VlnhVn(end+1,:) = [V(i) ln(j) h(k) Vn(u) i j k u];
end
end
end
end
end
end
the code doesn't give any results at all. It's really frustrating
Roger Stafford
Roger Stafford le 27 Déc 2012
My comment remains roughly the same as it was before. You now have one equation and four unknowns to vary: Ln, Vn, V, and h. Setting f to 58.4 will still leave an enormous three-dimensional space in which the unknowns can vary.
It is possible to manipulate with your equation so as to isolate h on one side of an equivalent equation with everything else on the other side. Then as you vary Ln, Vn, and V you will get all possible solutions. Beware however - three degrees of freedom take a lot of exploring. For example if each of the three take on a hundred possible values, that gives you a combined total of a million solutions to ponder over. I have a feeling you have better things to devote your time to.
By the way, your attempt to explore that four-dimensional space with four nested for-loops would have to go through over two billions steps. That may account for why you didn't succeed with it. However it might have helped if you had allocated space for VlnhVn before entering the loops.
Roger Stafford

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements 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