matlab, how do i write a statement that will give me time on xaxis from y=0.3

前端 未结 5 1261
情书的邮戳
情书的邮戳 2020-12-11 22:34
x=[0:.01:10];
y=(x.^2).*(exp(-x));

plot(x,y), grid
y1=max(y);

xlabel(\'TIME\');
ylabel(\'CONCENTRATION IN BLOOD\');
title(\'CONCENTRATIN OF SUSTANCE IN BLOOD vs TI         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-11 22:40

    If you have the symbolic toolbox in MATLAB, you can do the following

    syms x
    x=solve('x^2*exp(-x)=y')
    
    x=
      (-2)*lambertw(k, -((-1)^l*y^(1/2))/2)
    

    Here lambertw is the solution to y=x*exp(x), which is available as a function in MATLAB. So you can now define a function as,

    t=@(y,k,l)(-2)*lambertw(k, -((-1)^l*y^(1/2))/2)
    

    lambertw is a multivalued function with several branches. The variable k lets you choose a branch of the solution. You need the principal branch, hence k=0. l (lower case L) is just to pick the appropriate square root of y. We need the positive square root, hence l=0. Therefore, you can get the value of t or the time for any value of y by using the function.

    So using your example, t(0.3,0,0) gives 0.8291.

    EDIT

    I forgot that there are two branches of the solution that give you real outputs (gnovice's answer reminded me of that). So, for both solutions, use

    t(0.3,[0,-1],0)
    

    which gives 0.8921 and 3.9528.

提交回复
热议问题