How can i plot an inline function?

3 Ansichten (letzte 30 Tage)
Muhammad Usman
Muhammad Usman am 4 Nov. 2019
Beantwortet: Adam Danz am 4 Nov. 2019
I wrote a code in which i got and inline function as
U =
Inline function:
U(p,t,x) = (372863112183097.*exp(500.*x - 250.*t).*(sinh(1000.*sum(((-1).^p.*p.*exp(-(555609333788003.*p.^2.*t)./56294995342131200).*(exp(pi.*p.*x.*(-i)).*(i./2) + exp(pi.*p.*x.*i).*(-i./2)))./((1884165843459159.*(p.^2 - 1).^2)./1208925819614629174706176 + (5825986127860891.*p.^2)./73786976294838206464 + 73792802280966067355./73786976294838206464), p == 1.n)) + 7017961089264186343289723609432566477005855403012763273460273598821737866336338749326047126764570042716934574784489366662785827208940701722862252654770355689539991848141850896551869806913239102400648200731032287182848.*sum(((-1).^p.*cos(pi.*x.*(p + 1./2)).*exp(-(555609333788003.*t.*(p + 1./2).^2)./56294995342131200).*(2.*p + 1))./((5825986127860891.*p)./73786976294838206464 + (1884165843459159.*(4.*p + 4.*p.^2 - 3).^2)./19342813113834066795298816 + (5825986127860891.*p.^2)./73786976294838206464 + 295177035109992130311./295147905179352825856), p == 1.n)))./2361183241434822606848
now I want to plot this function against
x=-1:0.2:1, t=0:0.4:2, p=1:200
Someone please help me to write the plot command. Thanks

Antworten (2)

Star Strider
Star Strider am 4 Nov. 2019
Use Anonymous Functions instead of inline objects, since inline objects are likely to be depricated soon.
There is a missing (multiplication?) operator, probably here (where the ↑ are):
U = @(p,t,x) (372863112183097.*exp(500.*x - 250.*t).*(sinh(1000.*sum(((-1).^p.*p.*exp(-(555609333788003.*p.^2.*t)./56294995342131200).*(exp(pi.*p.*x.*(-i)).*(i./2) + exp(pi.*p.*x.*i).*(-i./2)))./((1884165843459159.*(p.^2 - 1).^2)./1208925819614629174706176 + (5825986127860891.*p.^2)./73786976294838206464 + 73792802280966067355./73786976294838206464), p == 1.n)) + 7017961089264186343289723609432566477005855403012763273460273598821737866336338749326047126764570042716934574784489366662785827208940701722862252654770355689539991848141850896551869806913239102400648200731032287182848.*sum(((-1).^p.*cos(pi.*x.*(p + 1./2)).*exp(-(555609333788003.*t.*(p + 1./2).^2)./56294995342131200).*(2.*p + 1))./((5825986127860891.*p)./73786976294838206464 + (1884165843459159.*(4.*p + 4.*p.^2 - 3).^2)./19342813113834066795298816 + (5825986127860891.*p.^2)./73786976294838206464 + 295177035109992130311./295147905179352825856), p == 1.n)))./2361183241434822606848
and likely several other problems, since this appears not to be completely valid MATLAB code.
Beyond that, when the ‘U’ function is repaired, calculate it with:
x = -1:0.2:1;
t = 0:0.4:2;
p = 1:200;
[X,T,P] = ndgrid(x, t, p);
Uz = U(P,T,X);
However, plotting it may be another problem, since the surface plot functions can only plot 2D matrices as the third argument, and ‘Uz’ (as I call it here) is a 3D matrix.
When ‘U’ is running successfully, we can talk about plotting it.

Adam Danz
Adam Danz am 4 Nov. 2019
As explained in the documentation, inline() will be removed in the future. Use anonymous functions instead.
191104 105355-Construct inline object - MATLAB inline.png
Here's the form it should take
U = @(p,t,x) (372863112183097.*exp(500.*x - 250.*t).*(sinh(1000.*sum(((-1).^p.*p.*exp(-(555609333788003.*p.^2.*t)./56294995342131200).*(exp(pi.*p.*x.*(-i)).*(i./2) + exp(pi.*p.*x.*i).*(-i./2)))./((1884165843459159.*(p.^2 - 1).^2)./1208925819614629174706176 + (5825986127860891.*p.^2)./73786976294838206464 + 73792802280966067355./73786976294838206464), p == 1.n)) + 7017961089264186343289723609432566477005855403012763273460273598821737866336338749326047126764570042716934574784489366662785827208940701722862252654770355689539991848141850896551869806913239102400648200731032287182848.*sum(((-1).^p.*cos(pi.*x.*(p + 1./2)).*exp(-(555609333788003.*t.*(p + 1./2).^2)./56294995342131200).*(2.*p + 1))./((5825986127860891.*p)./73786976294838206464 + (1884165843459159.*(4.*p + 4.*p.^2 - 3).^2)./19342813113834066795298816 + (5825986127860891.*p.^2)./73786976294838206464 + 295177035109992130311./295147905179352825856), p == 1.n)))./2361183241434822606848;
x = -1:0.2:1;
t = 0:0.4:2;
p = 1:200;
y = U(p,t,x);
However, your function has 2 errors that must be fixed first:
U = @(p,t,x) (372863112183097.*exp(500.*x - 250.*t).*(sinh(1000.*sum(((-1).^p.*p.*exp(-(555609333788003.*p.^2.*t)./56294995342131200).*(exp(pi.*p.*x.*(-i)).*(i./2) + exp(pi.*p.*x.*i).*(-i./2)))./((1884165843459159.*(p.^2 - 1).^2)./1208925819614629174706176 + (5825986127860891.*p.^2)./73786976294838206464 + 73792802280966067355./73786976294838206464), p == 1.n)) + 7017961089264186343289723609432566477005855403012763273460273598821737866336338749326047126764570042716934574784489366662785827208940701722862252654770355689539991848141850896551869806913239102400648200731032287182848.*sum(((-1).^p.*cos(pi.*x.*(p + 1./2)).*exp(-(555609333788003.*t.*(p + 1./2).^2)./56294995342131200).*(2.*p + 1))./((5825986127860891.*p)./73786976294838206464 + (1884165843459159.*(4.*p + 4.*p.^2 - 3).^2)./19342813113834066795298816 + (5825986127860891.*p.^2)./73786976294838206464 + 295177035109992130311./295147905179352825856), p == 1.n)))./2361183241434822606848;
% follow the arrow > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ^^^^ and > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ^^^^
BTW, this function is a bit crazy. There's a 217 digit integer.... seems fishy.

Kategorien

Mehr zu Function Creation 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