How do i make a function with the question below?

조회 수: 12 (최근 30일)
Gharib Makki
Gharib Makki 2019년 2월 6일
댓글: Gharib Makki 2019년 2월 6일
This is the only problem I am having with my homework, can someone please show me the steps on how to do this question, Thank you
  댓글 수: 2
Bob Thompson
Bob Thompson 2019년 2월 6일
Generally, people on this forum don't like to directly answer homework questions, but would be happy to help you with something more specific you're stuck on.
I suggest adding any bits of code, or psuedo code, you may have along with a more specific question. If you don't have any code yet, explain what you do understand, and we can attempt to help you with the parts you don't.
Gharib Makki
Gharib Makki 2019년 2월 6일
For the function I have,
function [] = myFunPlotter(f,x)
f= @x sqrt(x.)+exp(sin(x))
end
the code so far I inputted is
x = 0:2*pi
[x,f] = myFunPlotter(f,x)
however I dont know how to use the function 'func2str' and 'sprintf' and what they are for

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

채택된 답변

Bob Thompson
Bob Thompson 2019년 2월 6일
편집: Bob Thompson 2019년 2월 6일
func2str is a command which converts a function class variable (i.e. your f variable) into a string class variable. A class is basically just the term for what type of data a variable is, and how matlab should work with the variable.
sprintf is a command which prints a string, and is usually used to combine characters, numbers, or other variables into the string.
I suspect you will need to make a slight adjustment to your function to designate your inputs and outputs.
function [x,f] = myFunPlotter(x)
f = @x sqrt(x.)+exp(sin(x));
end
EDIT*
After reading over the prompt again, I think they are looking for you to use the function to actually create the plot, but both the function and range of x should be defined outside the function. That way, it doesn't matter what your function, f, and variable range, x, are and myFunPlotter can be used for any function.

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by