Clear Filters
Clear Filters

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

1 view (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 30 Jan 2018
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 Comments
Anas Deiranieh's
Anas Deiranieh's on 30 Jan 2018
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 on 30 Jan 2018
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!