Clear Filters
Clear Filters

Can somebody help me get this to work in a loop???

2 views (last 30 days)
I'm trying to solve momentum transfer for a range of data. The basis of the script is:
  • Output a value as the phase angle (Th_D) shifts from 0 to 360
  • This, along with some other data, is solved using the simultaneous operator solve( ) ( 2 equations so 2 outputs )
  • The 2 outputs from solve are placed into a separate matrix that I can manipulate later
Or, to place it into steps:
  1. Calculate the value of Veff at phase angle Th_D (store the output in a matrix)
  2. From a specified value of Veff ( 2nd value in every column) substitute it into solve( )
  3. solve() will output this value and store it in B1 and B2
  4. k is increased and the loop restarts
  5. New value of phase angle is used to compute Veff.. etc
I can get the script to work with just one value but I've been struggling for the past 3 hours to get it to work in a loop.
A=5E-6; % amplitude
Freq=20000;
w=Freq*2*pi; % angular frequency
Th_D=(0:1:360);
th=(Th_D .* (pi/180)); % phase angle radian
t=[0:2E-7:7.2E-5]; % time
for k=1:length(th)
Vt=-A*w;
Veff(k,:)=Vt.*sin(w.*t + th(k)); % Horn tip velocity
Vx=Veff(:,2);
Ue=Vx;
Uf=0;
Meff=10;
Mfr=20;
syms Ve Vf
B(k)=solve(Meff.*Ue(:,k) + Mfr*Uf==Meff*Ve + Mfr*Vf,...
Meff.*Ue(:,k).^2 + Mfr*Uf^2==Meff*Ve^2 + Mfr*Vf^2);
B1(k)=B(k).Ve; % effective mass output
B1_M(k)=double(B1);
B2(k)=B(k).Vf; % free mass output
B2_M(k)=double(B2);
end
Any help would be appreciated!!!

Answers (1)

Walter Roberson
Walter Roberson on 29 Nov 2013
You have
Vx = Veff(:,2)
which selects a single column out of Veff and writes it to Vx, so Vx will be a single column.
You then have
Ue = Vx
so Ue will have a single column.
You then attempt to access Ue(:,k) . That can only work if k is 1: as soon as k gets to 2, you would be attempting to access column 2 of something that only has one column.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!