How can i plot this symbolic function?

2 views (last 30 days)
Volli
Volli on 16 Jun 2017
Commented: Volli on 20 Jun 2017
Hello guys,
I have the following code, which calculates the Taylor-Polynom third degree of a user-given function around the point 0,0. (Also user given, but this is my test-case)
syms x y;
%f = input('Bitte geben Sie die zu evaluierende Funktion ein:','s');
f = 'exp(x^2+y^3)+x*y*(x+y)';
f = sym(f);
f = symfun(f, symvar(f, 2));
a = 0;
b = 0;
fx = diff(f,x);
fy = diff(f,y);
fxx = diff(fx,x);
fyy = diff(fy,y);
fxy = diff(fx,y);
fxxx = diff(fxx,x);
fxxy = diff(fxx,y);
fxyy = diff(fxy,y);
fyyy = diff(fyy,y);
fa = f(a,b);
fxa = fx(a,b);
fya = fy(a,b);
fxxa = fxx(a,b);
fyya = fyy(a,b);
fxya = fxy(a,b);
fxxxa = fxxx(a,b);
fxxya = fxxy(a,b);
fxyya = fxyy(a,b);
fyyya = fyyy(a,b);
t = @(x,y) fa + fxa .* (x-a) + fya .* (y-b) + 1/2 .* fxxa.*(x-a).^2 + 1/2 .* fxya .* (x-a).*(y-b) + fyya .* (y-b).^2 + 1/6 .* fxxxa .* (x-a).^3 + 1/2 .* fxxya .* (x-a).^2.*(y-b) + 1/2 .* fxyya .* (x-a).*(y-b).^2 + 1/6 .* fyyya .* (y-b).^3;
What I want to do is, plotting t. I tried different plotter but they all take an enormous amount of time, and then throw the error: Too many input arguments. But: all values (fa,fxa..., a,b) are assigned, so technically there are only two variables: x and y. Do I have a fundamental understanding-problem or where is my mistake?
Thank you for your help!

Answers (1)

Sagar Doshi
Sagar Doshi on 20 Jun 2017
Use fsurf or fmesh.
I was able to plot 't' using both the functions in about less than 10 seconds. I think the time here is required for evaluating bunch of symbolic expressions and then plotting them.
Also try using ezplot if using older version of MATLAB.
  1 Comment
Volli
Volli on 20 Jun 2017
Thank you for your answer.
In the meantime I was able to solve the problem. (I totally forgott to mention it here.)
I used:
Taylor = subs(t);
ezsurf(t(x,y));
It was fast and correct.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!