evaluate multiple variables with matlab code, (relooping?)
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuesta aceptada
Walter Roberson
el 20 de Dic. de 2012
8 comentarios
Roger Stafford
el 27 de Dic. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!