Polar : ERROR: Data must be numeric, datetime, duration or an array convertible to double.
    조회 수: 5 (최근 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!