Insert this equation into a code

2 件のコメント

jonathan riley
jonathan riley 2020 年 4 月 14 日
notice (-0.04t) is an exponent of 'e'
jonathan riley
jonathan riley 2020 年 4 月 14 日

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

回答 (2 件)

Spectro
Spectro 2020 年 4 月 14 日

1 投票

It should be like this.
numerator = a*b;
denominator = pow2(b*cos(cos(t))) + pow2(a*cos(cos(t)));
r = (numerator/sqrt(denominator))*exp(-0.04*t);
For the calculation itself you have to declare a, b and t.

2 件のコメント

BN
BN 2020 年 4 月 14 日
+1
jonathan riley
jonathan riley 2020 年 4 月 15 日
it is telling me matrix dimensions must agree.
What is wrong?

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

BN
BN 2020 年 4 月 14 日

1 投票

Hi, I create it as a function:
function r = mifun(a,b,t)
%this function calculates r based on a and b and t as inputs
% Detailed explanation goes here
numerator = a*b;
first_part = (b*cos(cos(t)))^2;
second_part = (a*sin(sin(t)))^2;
denominator = first_part + second_part;
denominator = sqrt (denominator);
fraction = numerator/denominator;
r = fraction*exp(-0.04*t);
end

4 件のコメント

jonathan riley
jonathan riley 2020 年 4 月 15 日
when i typed this in there were no errors but nothing would graph.
This is what my command looks like;
t=0.0:2*pi*'n';
x = 'r'*cos(cos(t));
y = 'r'*sin(sin(t));
z = ('h'*t)/(2*pi*'n');
function r = mifun(a,b,t);
numerator = a*b;
first_part = (b*cos(cos(t)))^2;
second_part = (a*sin(sin(t)))^2;
denominator = first_part + second_part;
denominator = sqrt (denominator);
fraction = numerator/denominator;
r = fraction*exp(-0.04*t);
a = 20;
b = 10;
h = 18;
n = 5;
plot3(x,y,z,'r', 'linewidth', 0.1)
grid on
xlabel('x'); ylabel('y'); zlabel('z')
end
BN
BN 2020 年 4 月 15 日
Dear Jonathan,
It is necessary to first open a new blank scrip page then paste the function that I wrote completely to it; then you should save this scrip to the current folder with the name of mifun. After you save it, you can use it, for example:
r = mifun(3,2,4) % where 3 is a, 2 is b, and 4 is t
jonathan riley
jonathan riley 2020 年 4 月 15 日
perfect thank you!
BN
BN 2020 年 4 月 15 日
You are most welcome.

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

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

質問済み:

2020 年 4 月 14 日

コメント済み:

BN
2020 年 4 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by