How to perform differentiation in MATLAB?
Show older comments
I have the following function.

The F is a 1*4 matrix and it is given. w=2*pi*f where f=50 Hz. I need to find out the value of i. How can I write the code in MATLAB?
24 Comments
Torsten
on 14 Sep 2022
So you have to solve
F = 2/pi * pi/2 * i^2 * omega
for i ? Should be no problem, shouldn't it ?
Image Analyst
on 14 Sep 2022
Looks like integration. Where is this differentiation you're asking about? Can you attach your existing script with the paper clip icon? And if F came from somewhere, like a .mat file, attach that too.
Walter Roberson
on 14 Sep 2022
Does the
mean the derivative with respect to w times t? If so, that complicates matters: MATLAB's int() function can only integrate with respect to a variable, so a change of variables would need to be done
w is scalar, presumably t is scalar. So if F is 1 x 4, the implication would have to be that
is 1 x 4. But
is
which would be inner product of i with itself, which would fail for 1 x 4 vector i.
ANANTA BIJOY BHADRA
on 14 Sep 2022
Torsten
on 14 Sep 2022
Yes.
i = sqrt(F/omega)
ANANTA BIJOY BHADRA
on 14 Sep 2022
Torsten
on 14 Sep 2022
You are not able to solve
F = 2/pi * pi/2 * i^2 * omega
for i ?
Walter Roberson
on 14 Sep 2022
I do not think that is correct. That would be correct if the equation were int(i^2*w*t, t, 0, pi/2) but it is int(i^2, w*t, 0, pi/2) where the integration is with respect to w*t not with respect to t. It needs a change of variables, which would affect the integration bounds.
Walter Roberson
on 15 Sep 2022
I think the integral needs a change of variables from integral of i^2 d_wt over wt 0 to π/2, to become 1/w * integral of i^2 * du over u 0 to w*π/2.
That should then be 1/w * (i^2*u over 0 to w*π/2) which would be 1/w * (i^2 * (w*π/2 - 0)) which should work out to π/2*i^2
The complete formula multiplies by 2/π so that cancels the π/2 leaving just i^2
So the question then becomes to solve F = i^2
Dyuman Joshi
on 15 Sep 2022
But w (omega) is given to be a constant here. So d(wt) should become w*d(t).
I guess OP needs to confirm this.
Walter Roberson
on 15 Sep 2022
No, the derivative is not with respect to t, the derivative is with respect to ωt so the question is not how quickly i^2 changes with respect to t, but rather how quickly it changes with respect to ω*t
As far as I know, the rule
integral_{a}^{b} f(x) d(h(x)) = integral_{a}^{b} f(x) * dh/dx dx
is valid.
This would give
d(omega*t) = omega dt.
Nevertheless, I'm uncertain about what the OP really wants.
ANANTA BIJOY BHADRA
on 15 Sep 2022
Torsten
on 15 Sep 2022
And what is lambda ?
ANANTA BIJOY BHADRA
on 15 Sep 2022
ANANTA BIJOY BHADRA
on 15 Sep 2022
Because you didn't answer my questions satisfactory, I'll show you how to proceed to recover i if F is given by
F(x) = integral_{y=0}^{y=x} i^2(y) dy
Say at 0=y(1)<y(2)<...<y(n) you have values for F of the above equation and you search for i.
Then - with the help of the trapezoidal rule - you get
i(1) = 0
F(2) = (y(2)-y(1))*(i^2(1)+i^2(2))/2 -> i^2(2) = 2*F(2)/(y(2)-y(1)) - i^2(1) ->
i(2) = sqrt(F(2)*2/(y(2)-y(1)) - i^2(1))
F(3) = (y(2)-y(1))*(i^2(1)+i^2(2))/2 + (y(3)-y(2))*(i^2(2)+i^2(3))/2 = F(2) + (y(3)-y(2))*(i^2(2)+i^2(3))/2 -> (F(3)-F(2))*2 / (y(3)-y(2)) - i^2(2) = i^2(3) ->
i(3) = sqrt((F(3)-F(2))*2 / (y(3)-y(2)) - i^2(2))
In general you get the recursion
i(1) = 0
i(k+1) = sqrt((F(k+1)-F(k))*2 / (y(k+1)-y(k)) -i^2(k))
to recover i from F.
Walter Roberson
on 15 Sep 2022
Consider 
The integral from 0 to 1 of the constant 1 with respect to a quantity should obviously be 1. But if you say that d(5t) = 5*dt then you would integrate
which would give you the result 5 rather than 1. So you have to change to
as then the integral would be 5 and you would multiply that by the outer 1/5 to get an overall result of 1.
Did you read the Wikipedia page about Riemann Stietjes integrals ?
It's explicitly written there that integral_{x=a}^{x=b} f(x) dg(x) = integral_{x=a}^{x=b} f(x) g'(x) dx.
Thus for the above integral integral_{x=0}^{x=1} 1 d(5*x) = integral_{x=0}^{x=1} 1*5 dx = 5.
But I think for the OP omega*t is just an integration variable u. Thus
integral_{omega*t=0}^{omega*t=pi/2} i^2(omega*t) d(omega*t) = integral_{u=0}^{u=pi/2} i^2(u) du
It seems that the notation of
is ambigous for definite integral and the notation is not widely used (correct me if I am wrong) since one does not know whether the integral limit is for variable x or for function
. To make it clear, one can write
but it is cumbersome. Of course, there is no issue for indefinete integration where integral limits are not relevant.
So we must understand the convention used.
where integral limits are for t and not for
or
.
The expression is clear enough and we know the integral limits are for variable t.
But I am not sure whether this is a general convention.
It's the general convention - the independent variable (limit of integration) is always x (or t).
The form of integral is often used in measure theory where integration usually is with respect to general measures, not only with respect to Lebesgue-measure (which is the usual integration (dx)).
E.g. for a random variable X with cumulative distribution function F(x), one often writes
P(X<=x) = integral_{y=-oo}^{y=x} dF(y)
which means
P(X<=x) = integral_{y=-oo}^{y=x} f(y) dy
where f = F' is the probability density function of the random variable X.
But I doubt that the OP had this in mind - in my opinion, omega*t is just meant as one compact integration variable u:
integral_{omega*t=0}^{omega*t=pi/2} i^2(omega*t) d(omega*t) = integral_{u=0}^{u=pi/2} i^2(u) du
Torsten
on 16 Sep 2022
Maybe you could show us how you compute F given i
(e.g. for your example F=[0 0.4409 1.1809 3.1570], i=[0 0.6235 2.7238 7.2487]) )
Answers (1)
Ganesh Gudipati
on 21 Sep 2022
0 votes
Hi,
You can rewrite the equation you have in order to find "i". Then you use diff function.
Since "F" is an array in this case you have to perform for each element individually. So "i" will also end up as an array.
I hope this resolves your issue.
Thanks.
Categories
Find more on Mathematics and Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
