Trying to take a generated set of values in a matrix and add to it.

1 次查看(过去 30 天)
I'm trying to take the values I generate and use them for the next iteration of calculations and add a new column with the results for each iteration. The idea is Resistance. Note since the resistances are the same, the parallel resistance might look weird.
Another problem is that I only get zeros. How can I get those small values to show?
clear all
% CONSTANTS
mu = 18.27E-6; % Viscosity
x = 8*mu/pi; % Constants
D = 0.0018; % Branch Diameter in meters
NumPerGen = 1; % Starting at Generation 1
R = D/2; % Branch Radius in m
L = 3*D; % Branch Length in m 3:1 Length/Diameter ratio
for i = 1:24
Res = x*L/R^4;
ParaRes = Res/NumPerGen;
if i == 1
A(:,i) = [i,Res,ParaRes,NumPerGen,D,L];
else
A(:,i) = [i,Res + A(2,i-1),ParaRes,NumPerGen,D,L];
end
D = 0.79*D; % 21% Reduction in diameter
NumPerGen = 2*NumPerGen; % Doubles with each generation
end

采纳的回答

Star Strider
Star Strider 2018-1-30
Your code runs without error, and while some values of ‘A’ are small, none appear to be zero. (Use format short E rather than format short to see the element values. See the documentation on the format (link) function for details.)
What is it doing that you don’t want it to do, or what is it not doing that you do want it to do?
  2 个评论
Anas Deiranieh's
Anas Deiranieh's 2018-1-30
buhahaha. . . in trying to shorten the mess I had before and make it more understandable for quicker help, I think I actually fixed it. Didn't realize it until you answered too! But yeah, you definitely answered my next question before I even asked it.
I think now at this point, I just want assistance with adding row labels if at all possible so I can print it out.
Star Strider
Star Strider 2018-1-30
Always here to help!
As for printing out your results with the row labels, see the documentation for fprintf (link) and the related sprintf (link) functions.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by