How to perform differentiation in MATLAB?

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

So you have to solve
F = 2/pi * pi/2 * i^2 * omega
for i ? Should be no problem, shouldn't it ?
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.
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.
I have the F value provided in the image. I need to find the i using the integral equation also given in the attched image.
But I need to do that using the matlab code.
Can you elaborate how do you get i = sqrt(F/omega)? Actually, I am not getting the exact idea.
You are not able to solve
F = 2/pi * pi/2 * i^2 * omega
for i ?
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.
Torsten
Torsten on 14 Sep 2022
Edited: Torsten on 14 Sep 2022
I must admit that I don't understand the notation.
So my "simple" solution was a kind of attempt to make the OP correct it and clarify his question.
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
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.
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.
The derivative is respect to (omega*t), not t. Actually it is integration of a nonlinear function. But I know th value of F at any instance, I need to calculate the value of i. The relation between F and i are in integral form. I have attached another image for clarification.
And what is lambda ?
lambda is the flux. actually it is a saturation curve. I can get the values of lambda from another equation. But it was not possilble for me to extract the value of i from the integral equation. I know the value of F at any instant. Using the value of F and the integral equation that I have shared, I need to find the value of i. I hope I was able to clarify.
Torsten
Torsten on 15 Sep 2022
Edited: Torsten on 15 Sep 2022
I'm still uncertain how the integral is evaluated. Could you give an example ?
What are the physical units of F and i ?
How is the "flux" related to the other variables ?
F comes from an array. If you see the previous image, you can see the value of F and 4 instance. I need to find the value of i at those four instance using the integral equation. the omega=2*pi*f whwre f=50Hz. The flux has nothing to do with i. For testing purpose, I have a known set of i which is generated from the F. See the below values:
F=[0 0.4409 1.1809 3.1570]
i=[0 0.6235 2.7238 7.2487]
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.
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.
Torsten
Torsten on 16 Sep 2022
Edited: Torsten on 16 Sep 2022
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
Chunru
Chunru on 16 Sep 2022
Edited: Chunru on 16 Sep 2022
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
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]) )

Sign in to comment.

Answers (1)

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.
You can refer the Differentiation documentation.
I hope this resolves your issue.
Thanks.

Categories

Find more on Mathematics and Optimization in Help Center and File Exchange

Products

Release

R2021a

Asked:

on 14 Sep 2022

Answered:

on 21 Sep 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!