random values and plot

evaluate (x.^3 + x.^(1/4)) .* exp(-2*x) for x = -6:0.2:3
a) Add random variables to each evaluated values.
b) Plot the results against the distribution of x.
HOW I write a and b question ?

5 件のコメント

Dyuman Joshi
Dyuman Joshi 2023 年 10 月 28 日
I assume you have to do this homework assignment on MATLAB.
What exactly does "random variables" mean?
Alptekin
Alptekin 2023 年 10 月 28 日
it will be values
Alptekin
Alptekin 2023 年 10 月 28 日
yes it will be done in matlab
John D'Errico
John D'Errico 2023 年 11 月 25 日
I see that having gotten an answer to your first question where you made no attempt at all to solve it, now you have posted two new questions, those questions just directly copied from your homework assignment, no effort made at all. I closed them, and will close any future question of that form from you.
Dyuman Joshi
Dyuman Joshi 2023 年 11 月 25 日
@John D'Errico, I don't remember this thread fully, however, given the first sentence of my answer, I feel like there should have been a comment from OP showcasing their attempt writing the code for their problem.
That response might have been deleted afterwards.

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

回答 (1 件)

Dyuman Joshi
Dyuman Joshi 2023 年 10 月 28 日

0 投票

In the code you have written, you are over-writing result in each iteration.
Preallocate the variable and use the loop index to save the value produced in each iteration.
x = -6:0.2:3;
n = numel(x);
%Preallocation
result = zeros(size(x));
for k = 1:n
result(k) = (x(k).^3 + x(k).^(1/4)) .* exp(-2*x(k));
end
random_values = randn(1, n);
results_with_random_values = result + random_values;
%plot
plot(x, results_with_random_values)
Warning: Imaginary parts of complex X and/or Y arguments ignored.
Another method is to obtain result is via Vectorization -
x = -6:0.2:3;
result = (x.^3 + x.^(1/4)) .* exp(-2*x);
random_values = randn(1, numel(result));
results_with_random_values = result + random_values;
%plot
plot(x, results_with_random_values)
Warning: Imaginary parts of complex X and/or Y arguments ignored.

1 件のコメント

Alptekin
Alptekin 2023 年 10 月 28 日
thank you

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

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2023 年 10 月 28 日

コメント済み:

2023 年 11 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by