how to write a formula in matlab including different variation
18 ビュー (過去 30 日間)
古いコメントを表示
hey guys im new in matlab i try to write a fourmula with some variation in matlab but as i said im so new here. could you please help me with
A= EXP^ (PI/3)* R/X
THATS A PART OF FORMULA here r has difrent value
0 件のコメント
採用された回答
Star Strider
2019 年 10 月 6 日
First:
A = exp(pi/3)*r./x; % Statement
A = @(r) exp(pi/3)*r./x; % Anonymous Function
3 件のコメント
Star Strider
2019 年 10 月 6 日
As always, my pleasure.
I am not certain what you are asking. Taking a guess:
Out = -R.*V.*(1+A(R)).^2)./(3*X.^2)
You left out several operators that I assume are implicit multiplication, so I used the vectorised multiplication operator (.*), and vectorised the rest of that expression as well (.^, ./).
Note that:
V(1+A)
will otherwise be interpreted as the (1+A) element of the V vector, and that will only work if A(R) returns an integer value >=0.
その他の回答 (5 件)
moji abb
2019 年 10 月 6 日
13 件のコメント
Star Strider
2019 年 10 月 8 日
Again, my pleasure.
Please code the equation, and post the code back here. It would be helpful if you also include the values of the variables.
moji abb
2019 年 10 月 10 日
2 件のコメント
Star Strider
2019 年 10 月 10 日
I made a few small changes to get your code to run with different values of ‘X’ as well as different values of ‘R’. This involves adding a loop and changing some of the indexing.
Your code is otherwise essentially unchanged:
%%% ====== input values =========
U = 12;
% R = 2; % change from R=0,1,2,3
L = [2200e-6; 2.9e-3; 3.8e-3]; % change from 0.0022 to 0.0045 in mH
frequency = 400; % in Hz, maybe 50Hz.
fi = pi/3;
Er = 8;
ksi = 0.1;
Xv = 2*pi*frequency*L; % ‘X’ is now vector ‘Xv’
r = [];
y = [];
Rv = 0:0.1:3; % ‘R’ is now vector ‘Rv’
figure
hold all
for k1 = 1:numel(Xv)
X = Xv(k1); % ‘X’ is an element of ‘Xv’ in each loop iteration
for k2 = 1:numel(Rv)
R = Rv(k2);
r(k1,k2) = R;
a = exp((R/X)*(pi/3));
k = R/X;
alfa = atan(X/R);
alfa1 = alfa*0.017;
output = -R*U*(1+a)^2*exp(-k*(fi-pi/3))/(3*X^2*(1+a^3))+Er*sin(fi-ksi-alfa1)/sqrt(R^2+X^2);
y(k1,k2) = output;
end
plot (r(k1,:), y(k1,:))
OutpLeg{k1} = sprintf('Output L = %.1f mH', L(k1)*1000);
end
hold off
legend(OutpLeg)
xlabel('R'), ylabel('output')
title('gragh R\_output')
Experiment to get the result you want.
moji abb
2019 年 10 月 10 日
7 件のコメント
Star Strider
2019 年 10 月 15 日
I am having a very difficult time understanding what you want to do.
Apparently, you need to re-arrange your equations for your dependent variable as a function of ‘L’ as the independent variable. The easiest way to do this is to use the Symbolic Math Toolbox.
I cannot do that for you because I do not understand your equations or what you want to do with them.
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
