USer Defined Function problem

5 ビュー (過去 30 日間)
A M Saif Ben Kabir Amit
A M Saif Ben Kabir Amit 2020 年 4 月 19 日
編集済み: Ameer Hamza 2020 年 4 月 21 日
Write a user-defined MATLAB function named PBTask4p1_f.m for the following math function with x the input argument and y the output: ?(?) = 3.2? 4 − 5? 2 − 7? The function should work for x being a scalar or a vector.
Use the function to calculate y(-5) and y(4) and display the results in command window b) Use the function to make a plot of the function y(x) for -5 ≤ x ≤ 5. Label the x-axis and y-axis of the plot like the one as follows.
I am new at Matlab ,Any help would be appriciated.Thank you
  4 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 4 月 20 日
What does not work? What is the error? Also, you function only need output 'w', why have you put 'z' in the output arguments.
A M Saif Ben Kabir Amit
A M Saif Ben Kabir Amit 2020 年 4 月 20 日
編集済み: Ameer Hamza 2020 年 4 月 20 日
function w=PBTask4p1(x)
w=3.2*x^4-5*x^2-7^x
end
PBTask4p1_f(-5)
w =1.8750e+03
ans =1.8750e+03
>> PBTask4p1_f(4)
w =-1.6618e+03
ans =-1.6618e+03
I got these output after removing the z from output.
Now how can I plotfrom this instruction (Use the function to make a plot of the function y(x) for -5 ≤ x ≤ 5.)
Thank You
>>

サインインしてコメントする。

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 20 日
Since you have already written the function, let me give you some information. In MATLAB '*' is used to indicate matrix multiplication. To do scalar multiplication, change the '*' operator in your code to '.*'. Like this
function w=PBTask4p1(x)
w = 3.2.*x.^4 - 5.*x.^2 - 7.^x;
end
Then create a vector of x values. Some thing like this
x = -5:0.1:5;
The use this x as input to PBTask4p1 and save the output in a variable. And then you can use plot() function
plot(x,w)
to create a plot.
  4 件のコメント
A M Saif Ben Kabir Amit
A M Saif Ben Kabir Amit 2020 年 4 月 21 日
Ok I got it now.Thank You for your kind help.
Ameer Hamza
Ameer Hamza 2020 年 4 月 21 日
I am glad to be of help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by