How do i make a function with the question below?

15 ビュー (過去 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 Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by