필터 지우기
필터 지우기

what is inline(vectorize function), also why to use fliplr for this?

조회 수: 10 (최근 30일)
Dhairya
Dhairya 2022년 11월 14일
댓글: Walter Roberson 2022년 11월 15일
clc
clear all
close all
syms x
f = input('Enter the function')
fL = input('Enter the interval on which the function is defined')
yr = input('Enter the axis of rotation')
iL = input('integration limits')
volume = pi*int((f-yr)^2,iL(1),iL(2));
disp(['Volume is: ',num2str(double(volume))])
fx = inline(vectorize(f));
xvals = linspace(fL(1),fL(2),201);
xvals = fliplr(xvals);
xivals = linspace(iL(1),iL(2),201);
xivalsr = fliplr(xivals);
xlim = [fL(1) fL(2)+0.5];
ylim = fx(xlim);
figure('Position',[100 200 560 420])
subplot(2,1,1)
hold on
plot(xvals,fx(xvals),'-b','LineWidth',2);
[X,Y,Z] = cylinder(fx(xivals)-yr,100);
figure('Position',[700 200 560 420])
Z = iL(1) + Z.*(iL(2)-iL(1));
surf(Z,Y+yr,X,'EdgeColor','none','FaceColor','flat','FaceAlpha',0.6);
hold on
plot([iL(1),iL(2)],[yr yr], 'r-', 'LineWidth', 2);
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
view(22,11)

채택된 답변

Chandler Hall
Chandler Hall 2022년 11월 14일
편집: Chandler Hall 2022년 11월 14일
Vectorize just adds some '.' to a string so that it might be used as a vectorized function, i.e.,
>> vectorize('(x^3)/y')
ans =
'(x.^3)./y'
Why use fliplr? That's impossible to say because it actually has no effect at all. xvals is only used in the subsequent plot, which produces the same output if the vectors are in ascending order vs descending, and xivalsr is unused.
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 11월 15일
Changing the order using fliplr() could potentially lead to a difference as to exactly where the "seam" is in the plot of the cylinder.

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

추가 답변 (1개)

Steven Lord
Steven Lord 2022년 11월 14일
Do not use inline. Its use has been discouraged for probably around 15 years now.
To convert a piece of text data to something that you can call as a function use str2func.
To convert a symbolic expression to something that you can call as a function use matlabFunction.
  댓글 수: 2
Dhairya
Dhairya 2022년 11월 14일
sir we have an exam tomorrow and this the only way we are taught
if possible could you please give some description about it?
Steven Lord
Steven Lord 2022년 11월 15일
See the documentation for str2func and matlabFunction for examples of how to use each function.

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

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by