How to display variables on MATLAB plots

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 3K views
frejatroop
Messages
1
Reaction score
0
The question gives the code for MATLAB to solve Hill equation with 5 different values of distance x, which will generate 5 plots on same axis. But the plots will be Force versus time. The question ask you to interpret the relationship between X and F(t).

How do I know this plot represents which value of x?
2. Given code with fixed variable for Hill model equation Bolded line is the distance which I'd like to show it on plots

clear
global kpe kse b xstar x delay A tv
kpe = 75; % spring constant of parallel element, g/cm
kse = 136; % spring constant of series element, g/cm
b = 50; % viscosity of parallel dashpot, (g*s)/cm
delay = 0.1; % delay before stimulation, s
xv = [1 1.5 2 2.5 3.0]; %fixed length in cm
xstar = 1; % resting length, cm
tspan = [0 .5]; % time span, s

% pre-calculate the activation function A(t)
dtv = 0.0001;
tv = [tspan(1):dtv:tspan(2)];
A = 1*(tv>delay).*(48144*exp(-(tv-delay)/0.0326) - 45845*exp(-(tv-delay)/0.034));

cvect ='bgrck';
figure
hold

AND code for ODE
function dFdt = hill_isometric_rhs(t,F)
global kpe kse b xstar x delay A tv

% scaling function for A(t) as a function of length
s = (x>0.5*xstar)*(x<1.5*xstar)*(cos(pi*(x-xstar)));

% instead of calculating A(t), use precalculated version
%Aloc = 1*(t>delay)*(48144*exp(-(t-delay)/0.0326) - 45845*exp(-(t-delay)/0.034));
% imin = index of nearest match to current value of t
% using a fine grid, no need to interpolate
[tmin,imin]=min(abs(tv-t));
Aloc = A(imin);

dFdt = kse/b*(kpe*(x-xstar)*(x>xstar) - (1+kpe/kse)*F + Aloc*s);

The Attempt at a Solution


I tried using
for i=1:length(xv)
x = xv(i);
F0 = (x>xstar)*kpe*(x-xstar)/(1+kpe/kse);
[t,F]=ode15s('hill_isometric_rhs',tspan,F0);
plot(t,F,cvect(i))
text(t, F, ['Distance is: ', num2str(x)]);

Q = quotation(rand);
if isempty(Q); error('Quotation server filesystem problems')
else sprintf('%s',Q), end


end

But it only shows one line, while without the italic part, 5 plots are generated normally
 
Physics news on Phys.org
Use the
Code:
 [CODE] [ /CODE]
(without the space after the bracket in \CODE to put your code into a code-box.