How can I plot this piecewise function? Can someone explain what I am missing?

Can someone explain what I am missing? I am not quite sure what the error is.
syms x
syms y
f_y=1./(3*sqrt(y))
f_y = 
f_y_plot=piecewise(x < 0,0,x > 0,f_y)
f_y_plot = 
fplot(f_y_plot)
Error using fplot>singleFplot
Input must be a function or functions of a single variable.

Error in fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 200)
hObj = cellfun(@(f) singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);

Error in fplot>vectorizeFplot (line 200)
hObj = cellfun(@(f) singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);

Error in fplot (line 166)
hObj = vectorizeFplot(cax,fn,limits,extraOpts,args);

댓글 수: 1

What is the relation between x and y? If there isn't you might have to use other methods to plot what you want to plot, as fplot requires input function to be of single variable as shown in the error.

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

답변 (1개)

Youssef Noureddine
Youssef Noureddine 2022년 11월 9일
Hi Tony,
As mentioned by DJ, fplot is a 2-D plot that can only show the relationship of a variable against one other variable. Your example 'f_y_plot' depends on both the values of x and y. I would take another look at how you have defined the equations if you intended the variable to only depend on one of them. Otherwise I would recommend the use of other functions that let you plot a variable that is a function of more than one variable. Refer to the following functions: fcontour, fmesh, fsurf (and potentially fplot3) for plotting of the form z = f(x,y) and decide on which is most optimal based on your use case.
I've attached the links to all the functions for convenience:
https://www.mathworks.com/help/matlab/ref/fcontour.html
https://www.mathworks.com/help/matlab/ref/fmesh.html
https://www.mathworks.com/help/matlab/ref/fsurf.html
Sincerely,
Youssef

카테고리

도움말 센터File Exchange에서 Graphics에 대해 자세히 알아보기

태그

질문:

2022년 11월 7일

답변:

2022년 11월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by