필터 지우기
필터 지우기

I have troubles in understanding how could I turn some data type sym variables into data type symfun, can anybody make it clear for me?

조회 수: 2 (최근 30일)
% This program computes for the Tangent Line / Normal Line of a curve % about a given point
%define x for symbolic processing
syms x
%IDENTIFY the function f(x)
f(x) = (4*x^2-2*x+1);
%DETERMINE the point of tangency (This will be a random point)
x0=randi([-5,5])
%SOLVE for the Ordinate of the point of tangency
y0=f(x0); %Evaluate y given value fo x
y=73;
%FIND the slope function
yprime= diff(f,x) %Solve for the first derivative
%Determine the slope at the given x0
m=yprime(x0); %sym(-42); %Evaluate the slope
%Solve the equation of the tangent line
ytangent = -42*x+1/42
%Solve the Equation of the normal line
ynormal = 1/42*x+215/42
%DISPLAYING RESULTS
fprintf('The tangent line to f(x)=%s at (%.2f, %.2f) is y = %s \n',string(f(x)),x0,y0, string(ytangent))
fprintf('The normal line to f(x)=%s at (%.2f, %.2f) is y = %s \n',string(f(x)),x0,y0, string(ynormal))
%PLOTTING
g1=ezplot(f,[-15,15]);
set(g1,'color','b')
grid on
hold on
plot(x0,y0,'r*')
text(x0+1,y0,"Point of Tangency")
g2=ezplot(ytangent,[-15,15]);
text(5,5,["y(Tangent)=", string(ytangent)])
pause(1)
set(g2,'color','m')
pause(1)
g3=ezplot(ynormal,[-15,15]);
text(3,3,["y(Normal)=", string(ynormal)])
set(g3,'color','c');
title("Tangent Line and Normal Line")
Errors:
Variable m must be of data type symfun. It is currently of type sym. Check where the variable is assigned a value.
Variable ytangent must be of data type symfun. It is currently of type sym. Check where the variable is assigned a value.
Variable ynormal must be of data type symfun. It is currently of type sym. Check where the variable is assigned a value.
  댓글 수: 4
Cris LaPierre
Cris LaPierre 2023년 3월 29일
Where is it saying this? I'm not seeing it in 23a. What version of MATLAB are you using?
Cris LaPierre
Cris LaPierre 2023년 3월 29일
Adding (x) will turn your sym variables into sym functions btw
syms x
f(x) = (4*x^2-2*x+1);
yprime= diff(f,x);
x0=randi([-5,5]);
m(x)=yprime(x0);
whos m
Name Size Bytes Class Attributes m 1x1 8 symfun

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 3월 29일
ytangent(x) = -42*x+1/42
%Solve the Equation of the normal line
ynormal(x) = 1/42*x+215/42

카테고리

Help CenterFile Exchange에서 Formula Manipulation and Simplification에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by