Polar : ERROR: Data must be numeric, datetime, duration or an array convertible to double.
3 次查看(过去 30 天)
显示 更早的评论
In this code I want to enter the function f(r) in terms of 'r' and then plot its figure with polarplot and calculate grad(f(r)) in terms of 'x,y' (I used chain theorem).
but when I run it and enter a function the following error occurs:
ERROR: Data must be numeric, datetime, duration or an array convertible to double.
Here is a code:
syms x y r;
f=input('enter function: ','s');
f = symfun(eval(f), r);
g=[-diff(f,r)*x*(x^2+y^2)^(-3/2),-diff(f,r)*y*(x^2+y^2)^(-3/2)];
f = str2func(['@(r)' vectorize(f)]);
[X,Y]=meshgrid(-10:.5:10);
figure
theta = 0:0.01:2*pi;
polarplot(theta,f(r));
what's the problem?
0 个评论
回答(1 个)
Walter Roberson
2017-5-24
You define f in terms of x and y, which are symbolic variables at the time you do the str2func(). You construct variables X and Y but you do not do anything with them. Yu construct theta, but you only use it as an arbitrary axes, disconnected from anything happening in f. You invoke f on the symbolic variable r.
Do not do the str2func: leave f as a symbolic formula, that you can then subs() values into. (But even then you have a disconnect between the mysterious theta, r, and X and Y.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!