1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: How to display variables on MATLAB plots

  1. Nov 1, 2014 #1
    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

    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';

    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
    Aloc = A(imin);

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

    3. 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);
    text(t, F, ['Distance is: ', num2str(x)]);

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


    But it only shows one line, while without the italic part, 5 plots are generated normally
  2. jcsd
  3. Nov 2, 2014 #2


    User Avatar
    Gold Member

    Use the
    Code (Text):
     [CODE] [ /CODE]
    (without the space after the bracket in \CODE to put your code into a code-box.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted