Creating a symbolic variable, then using it as a real variable
    조회 수: 6 (최근 30일)
  
       이전 댓글 표시
    
I need my program to calculate the derivative of a function, and as far as I understand that means I need to make a symbolic variable. How then can I continue to use that variable as a real vector?
This is what I have tried:
syms x
y = input('Please enter a valid function of x')
deriv = diff(y)
syms clear
x = 0:pi/30:pi;
plot(x,y)
댓글 수: 0
채택된 답변
  Matt Fig
      
      
 2012년 10월 25일
        
      편집: Matt Fig
      
      
 2012년 10월 25일
  
      syms x
y = input('Please enter a valid function of x: ')
deriv = diff(y)  % This will be symbolic
x = 0:pi/30:pi;  % Now x is a double.
y = matlabFunction(y)  % y is a function handle.
plot(x,y(x))
댓글 수: 2
  Matt Fig
      
      
 2012년 10월 25일
				
      편집: Matt Fig
      
      
 2012년 10월 25일
  
			y is a function handle (as I say in the comment!), not a vector. If you want to make y a vector instead:
syms x
y = input('Please enter a valid function of x: ')
x = 0:pi/30:pi;  % Now x is a double.
y = subs(y);  % y is now a double.
plot(x,y)
Or without the symbolic toolbox at all:
x = 0:pi/30:pi;
y = 'Please enter a valid function of x: ';
y = feval(vectorize(inline(input(y,'s'))),x);
plot(x,y)
추가 답변 (1개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


