# How to differentiate, then define a variable and integrate with respect to a different variable?

2 Ansichten (letzte 30 Tage)
Magnus am 8 Okt. 2014
Kommentiert: Magnus am 9 Okt. 2014
Dear community,
I'd like to create a function file in which I firstly differentiate a function Psi with respect to z. After differentiation, z is defined and becomes a function of x. The result shall then be integrated with resprect to x. So, something like
F=int(dPsi(x,z(x))/dz)dx
How do I do it in matlab? In mudpad, maple etc. it's obviously easy but I get stuck in Matlab because firstly, my symbolic z is a variable and then a function.
Any help is very appreciated.
Kind regards
##### 2 KommentareKeine anzeigenKeine ausblenden
Bruno Pop-Stefanov am 9 Okt. 2014
If you have an expression in MuPAD which does the differentiation then the integration, you can import it into MATLAB as a symbolic expression.
The following example page explains how to copy variables and expressions between MATLAB and MuPAD:
Magnus am 9 Okt. 2014
Yes, sure. Thanks. But I though of doing it all in one function to allow for changes in the function z(x) without doing mupad processing again.

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Bruno Pop-Stefanov am 9 Okt. 2014
I wrote a small example below and everything seems to work fine.
1. Define the function Psi
syms y
Psi(y) = 1 + y^2;
2. Differentiate it
dPsi = diff(Psi);
3. Define the z-function of x
syms x
z(x) = 1/x;
4. Integrate dPsi of z with respect to x
F = int(dPsi(z),x)
F =
2*log(x)
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Magnus am 9 Okt. 2014
ok, so a change of variables handle is the solution. Thanks, Bruno.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Conversion finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by