How can i plot this symbolic function?

2 次查看(过去 30 天)
Volli
Volli 2017-6-16
评论: Volli 2017-6-20
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!

回答(1 个)

Sagar Doshi
Sagar Doshi 2017-6-20
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 个评论
Volli
Volli 2017-6-20
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by