필터 지우기
필터 지우기

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