physics - Summing scalars and vectors [MATLAB] -
first off; i'm not taught in programming, tend learn need learn in order want when programming, have moderate experience python, html/css c , matlab. i've enrolled in physics-simulation course use matlab compute trajectory of 500 particles under influence of 5 force-fields of different magnitude.
so thing; need write following i=1...500 particles
f_i = m*g - sum{(f_k/r_k^2)*exp((||vec(x)_i - vec(p)_k||^2)/2*r_k^2)(vec(x)_i - vec(p)_k)}
i hope not cluttered
and here code far;
clear close echo off%simulation parameters-------------------------------------------
h = 0.01; %time-step h (s) t_0 = 0; %initial time (s) t_f = 3; %final time (s) m = 1; %particle mass (kg) l = 5; %charateristic length (m) nt = t_f/h; %number of time steps g = [0,-9.81]; f = [32 40 28 16 20]; %the force f_k (n) r = [0.3*l 0.2*l 0.4*l 0.5*l 0.3*l]; %the radii r_k p = [-0.2*l 0.8*l; -0.3*l -0.8*l; -0.6*l 0.1*l; 0.4*l 0.7*l; 0.8*l -0.3*l]; %forcefield origin position
%stepper = 'forward_euler'; % use forward euler time-integration
fprintf('simulation parameters set');
%initialization--------------------------------------------------- = 1:500 %gives inital value each of 500 particles particle{i,1}.x = [-l -l];
particle{i,1}.v = [5,10]; particle{i,1}.m = m;k = 1:5 c = particle{i}.x - p(k,:); f = rdivide(f(1,k),r(1,k)^2).*c %clear c; %creates elements array f end particle{i}.fi = m*g - sum(f); %compute attractive force on particle %clear f; %clear f next use end
what code seems goes first loop index i, goes through 'k'-loop , exits value f uses last value f(k) compute f_i. want put values of f(k) 1-5 , put matrix columns can sum f_i. i'd prefer sum columns first column should represent f-components in x-axis , second column f-components in y-axis.
note expression f in k-loop not done.
i fixed defining index f(k,:)
Comments
Post a Comment