Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Calculating 1st derivative with a parameter

Subject: Calculating 1st derivative with a parameter

From: Wojtek

Date: 6 May, 2012 14:21:07

Message: 1 of 5

Hello,
in my program I want to calculate the 1st derivative of a function y (it's a function of 'x1'). Let's say I want to check if the 1st derivative of this function in some specific point is smaller then 0.05. I have:

syms x1;
y = ( x1 - za )*( x1 - zb )*( x1 - zc )*( x1 - zd ); %my function, all the parameters like 'za' were previously declared

dydx=diff(y,x1,1);

    x_val=1;
    dydx_val=subs(dydx,x1,x_val);
    k2 = solve(dydx_val);
    dydx_val =double(k2);
    
    if (dydx_val<0.05)
        remember=x_val;
    end


unfortunately the derivative is not calculated. I get information:
Warning: 1 equations in 0 variables.
Warning: Explicit solution could not be found.
and when I try to display dydx_val i get:

dydx_val =

     []

I tried different methods, none of them was good (although I could do something wrong). I will be grateful for suggestions how can I calculate 1st derivative in a specific point and have the value of this derivative in double.

Subject: Calculating 1st derivative with a parameter

From: Angie

Date: 6 May, 2012 16:19:07

Message: 2 of 5

"Wojtek" wrote in message <jo61cj$m95$1@newscl01ah.mathworks.com>...
> Hello,
> in my program I want to calculate the 1st derivative of a function y (it's a function of 'x1'). Let's say I want to check if the 1st derivative of this function in some specific point is smaller then 0.05. I have:
>
> syms x1;
> y = ( x1 - za )*( x1 - zb )*( x1 - zc )*( x1 - zd ); %my function, all the parameters like 'za' were previously declared
>
> dydx=diff(y,x1,1);
>
> x_val=1;
> dydx_val=subs(dydx,x1,x_val);
> k2 = solve(dydx_val);
> dydx_val =double(k2);
>
> if (dydx_val<0.05)
> remember=x_val;
> end
>
>
> unfortunately the derivative is not calculated. I get information:
> Warning: 1 equations in 0 variables.
> Warning: Explicit solution could not be found.
> and when I try to display dydx_val i get:
>
> dydx_val =
>
> []
>
> I tried different methods, none of them was good (although I could do something wrong). I will be grateful for suggestions how can I calculate 1st derivative in a specific point and have the value of this derivative in double.

Hello,

If I understood your question correctly, you don't need the line for solve and the following seems to work for me:

syms za zb zc zd x1;
y = ( x1 - za )*( x1 - zb )*( x1 - zc )*( x1 - zd );

xVal = 1;

% Take the derivative and substitute the value of x1
focValue = subs(diff(y,'x1'),x1,xVal);

if focValue < 0.5
remember = focValue;
end

I hope this helps,

A.

Subject: Calculating 1st derivative with a parameter

From: Angie

Date: 6 May, 2012 16:25:08

Message: 3 of 5

"Angie" wrote in message <jo689r$idb$1@newscl01ah.mathworks.com>...
> "Wojtek" wrote in message <jo61cj$m95$1@newscl01ah.mathworks.com>...
> > Hello,
> > in my program I want to calculate the 1st derivative of a function y (it's a function of 'x1'). Let's say I want to check if the 1st derivative of this function in some specific point is smaller then 0.05. I have:
> >
> > syms x1;
> > y = ( x1 - za )*( x1 - zb )*( x1 - zc )*( x1 - zd ); %my function, all the parameters like 'za' were previously declared
> >
> > dydx=diff(y,x1,1);
> >
> > x_val=1;
> > dydx_val=subs(dydx,x1,x_val);
> > k2 = solve(dydx_val);
> > dydx_val =double(k2);
> >
> > if (dydx_val<0.05)
> > remember=x_val;
> > end
> >
> >
> > unfortunately the derivative is not calculated. I get information:
> > Warning: 1 equations in 0 variables.
> > Warning: Explicit solution could not be found.
> > and when I try to display dydx_val i get:
> >
> > dydx_val =
> >
> > []
> >
> > I tried different methods, none of them was good (although I could do something wrong). I will be grateful for suggestions how can I calculate 1st derivative in a specific point and have the value of this derivative in double.
>
> Hello,
>
> If I understood your question correctly, you don't need the line for solve and the following seems to work for me:
>
> syms za zb zc zd x1;
> y = ( x1 - za )*( x1 - zb )*( x1 - zc )*( x1 - zd );
>
> xVal = 1;
>
> % Take the derivative and substitute the value of x1
> focValue = subs(diff(y,'x1'),x1,xVal);
>
> if focValue < 0.5
> remember = focValue;
> end
>
> I hope this helps,
>
> A.

Correction and I forgot to mention something else:
0.05 instead of 0.5 and I assume you have numerical values for your za,zb,zc,zd parameters. In other words, if you put numerical values for za,zb,zc,zd (instead of syms za zb ...) you should be able to get your result.

A.

Subject: Calculating 1st derivative with a parameter

From: Wojtek

Date: 6 May, 2012 20:14:08

Message: 4 of 5

"Angie" wrote in message <jo68l4$jq1$1@newscl01ah.mathworks.com>...
> "Angie" wrote in message <jo689r$idb$1@newscl01ah.mathworks.com>...
> > "Wojtek" wrote in message <jo61cj$m95$1@newscl01ah.mathworks.com>...
> > > Hello,
> > > in my program I want to calculate the 1st derivative of a function y (it's a function of 'x1'). Let's say I want to check if the 1st derivative of this function in some specific point is smaller then 0.05. I have:
> > >
> > > syms x1;
> > > y = ( x1 - za )*( x1 - zb )*( x1 - zc )*( x1 - zd ); %my function, all the parameters like 'za' were previously declared
> > >
> > > dydx=diff(y,x1,1);
> > >
> > > x_val=1;
> > > dydx_val=subs(dydx,x1,x_val);
> > > k2 = solve(dydx_val);
> > > dydx_val =double(k2);
> > >
> > > if (dydx_val<0.05)
> > > remember=x_val;
> > > end
> > >
> > >
> > > unfortunately the derivative is not calculated. I get information:
> > > Warning: 1 equations in 0 variables.
> > > Warning: Explicit solution could not be found.
> > > and when I try to display dydx_val i get:
> > >
> > > dydx_val =
> > >
> > > []
> > >
> > > I tried different methods, none of them was good (although I could do something wrong). I will be grateful for suggestions how can I calculate 1st derivative in a specific point and have the value of this derivative in double.
> >
> > Hello,
> >
> > If I understood your question correctly, you don't need the line for solve and the following seems to work for me:
> >
> > syms za zb zc zd x1;
> > y = ( x1 - za )*( x1 - zb )*( x1 - zc )*( x1 - zd );
> >
> > xVal = 1;
> >
> > % Take the derivative and substitute the value of x1
> > focValue = subs(diff(y,'x1'),x1,xVal);
> >
> > if focValue < 0.5
> > remember = focValue;
> > end
> >
> > I hope this helps,
> >
> > A.
>
> Correction and I forgot to mention something else:
> 0.05 instead of 0.5 and I assume you have numerical values for your za,zb,zc,zd parameters. In other words, if you put numerical values for za,zb,zc,zd (instead of syms za zb ...) you should be able to get your result.
>
> A.

Hi, thanks for the answer!
Unfortunately when doing it your way I get an error:

??? Error using ==> sym.sym>notimplemented at 2653
Function 'lt' is not implemented for MuPAD symbolic objects.

Error in ==> sym.sym>sym.lt at 812
            notimplemented('lt');

Error in ==> myfile at 77
    if (dydx_val<0.05)

Additionally when I try to display the value of dydx_val I get:

dydx_val =
 
-(289129866313728*D(ceil)(965535013052404736/3125))/125

Subject: Calculating 1st derivative with a parameter

From: Christopher Creutzig

Date: 14 Jun, 2012 14:34:31

Message: 5 of 5

On 06.05.12 22:14, Wojtek wrote:

> Unfortunately when doing it your way I get an error:
>
> ??? Error using ==> sym.sym>notimplemented at 2653
> Function 'lt' is not implemented for MuPAD symbolic objects.

That was new in 2012a, I believe. You should be able to use “if
double(focValue) < 0.5” in earlier versions.

> Additionally when I try to display the value of dydx_val I get:
>
> dydx_val =
>
> -(289129866313728*D(ceil)(965535013052404736/3125))/125

I assume one of your input parameters (za, zb, zc, zd) contains a
symbolic “ceil” expression then. That is not differentiable in the
function sense. You may be able to get further by adding

dydx=subs(dydx,'D(ceil)',0);

after defining dydx. Just double-check that the result in the end looks
reasonable. For the value you showed, that would result in zero – if
that is not a good result, go back to your problem and clearly state
what the derivative of the ceiling function is supposed to be in this
situation.


Christopher

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us