solving a multiple variable equation with variables that increment

So my program is an attempt to create a simple wind tunnel simulator to test different projectiles. here is the script:
function answer = efficiency()
syms V C A
%% Drag force equation = (1/2)pV^2CA
%p = density of air = 0.00128 g/mL
%V = velocity = variable V
%C = Coefficient of drag = variable C
%A = Cross sectional area = function A
%F = 0.5 * 0.00128(g/mL) * V^2(m/s^2) * C * A(m)
%%Drag Coefficient
% Drag Coefficient of Sphere = 0.47
% Drag Coefficient of cone = 0.50
% Drag Coefficient of cube = 1.05
% Drag Coefficient of long cylinder = 0.82
% Selection of projectile shape
X = menu('projectile shape','sphere','cone','cube','cylinder','main menu');
if X == 1
C = 0.47;
elseif X == 2
C = 0.50;
elseif X == 3
C = 1.05;
elseif X == 4
C = 0.82;
elseif X ==5
C = WindTunnel();
end
%%Cross sectional area
% area of sphere = pi r^2
% area of cone = pi r^2
% area of cube = base * height
% area of long cylinder = pi r^2
for A = .1:.1:1
end
for V = 100:100:1000
end
answer = solve(.00064*C*A*V^2);
answer =
end
It is only outputing zeros for the solutions any help would be appreciated

 채택된 답변

Star Strider
Star Strider 2014년 6월 11일
I haven’t run your code, but two problems are immediately apparent:
First, these two lines will simply loop without doing anything, and return the last value of A and V respectively:
for A = .1:.1:1
end
for V = 100:100:1000
end
Second in this line:
answer = solve(.00064*C*A*V^2);
what are you solving for?
If you want ‘answer’ to be the result of that calculation, simply do:
answer = .00064*C*A*V^2;
If you want it for every value of A and V, you have to put it into nested loops and index it.
For example:
A = .1:.1:1;
V = 100:100:1000;
for k1 = 1:length(A)
for k2 = 1:length(V)
answer(k1,k2) = 0.00064*C*A(k1)*V(k2)^2;
end
end
Make necessary changes so it does what you want.
A third observation is that you don’t need to call the Symbolic Math Toolbox at all. It is not well-suited to iterative calculations, and you’re not doing anything with it.
The last line in your code is simply ‘answer =’. I assume that’s a typo in typing your Question, because it would throw an error at compilation and your code wouldn’t calculate anything.

댓글 수: 2

Awesome, that helped out perfectly. thank you very much

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2014년 6월 11일

댓글:

2014년 6월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by