how to write a formula in matlab including different variation

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

 Réponse acceptée

First:
A = exp(pi/3)*r./x; % Statement
A = @(r) exp(pi/3)*r./x; % Anonymous Function

3 commentaires

thank you so much i would like to ask you how can i adreess this value A in following formula
[-R*V(1+A)^2)/(3X^2)]
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.
please take a look on attached file im not sure if i wrote it right

Connectez-vous pour commenter.

Plus de réponses (5)

moji abb
moji abb le 6 Oct 2019
1.jpeg

13 commentaires

If this is the equation you want to use, first write it in MATLAB code.
Note that is written as:
exp(-k.*(phi-pi/3))
After you write it and get it working to your satisfaction (I will help you with that), and supply the necessary values for the constants, we can use the appropriate function to find one or more of the root values. Consider using the Symbolic Math Toolbox as well for this if you have access to it.
thank you i will text u for next step
Please keep all discussions related to this thread here. That creates a continuous narrative for others to follow.
sure. is it make sence now
output = -R*U*(1+a)^2*exp(-k*(fi-pi/3))/(3*X^2*(1+a^3))+Er*sin(fi-ksi-alfa)/sqrt(R^2+X^2);
im not sute about combination of angle and R and X value
That seems to be correct.
For best results, you need to vectorise it:
output = -R.*U.*(1+a).^2.*exp(-k.*(fi-pi./3))./(3.*X.^2.*(1+a.^3))+Er.*sin(fi-ksi-alfa)./sqrt(R.^2+X.^2);
Supply the necessary values and see if it produces the correct result.
got it thank you so much.
As always, my pleasure.
Hello again I simulated this but I'm struggling with this simple question for this equation " e^-k(alfa-pi/3)" Here k is constant value if drivation R/x(resistance/inductance) But the other side is an angle I'm not sure how to write and solve this, I appreciate if you help me with
We discussed how to code the exponential call here.
I do not understand what ‘the other side is an angle’ means. The equation you posted has part of an equal sign on the left, and on the right equals 0.
I guess I'm just confused with mathematics. I mean combination of pi and K . K= resistance/inductance and that is * by 2pi/2 -pi/2 I'm just confused with actual number with angle here , is it find to code like that.
First, 2*pi/2-pi/2 = pi/2. That much, at least, is solved.
I could code that expression for you (although I have no idea if the variables are scalrs, vectors, or matrices, and whether they are real, imaginary, or complex, so I could not guarantee that it would be correct), however the point is for you to learn how to code it. I will of course help you if you have problems coding it.
I appreciate your efforts
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.

Connectez-vous pour commenter.

moji abb
moji abb le 10 Oct 2019
LET ME write down value probablye gonna be more clear,
%%% ====== input values =========
U = 12;
% R = 2; % change from R=0,1,2,3
L =2200e-6; % change from 0.0022 to 0.0045 in mH
frequency = 400; % in Hz, maybe 50Hz.
fi = pi/3;
Er = 8;
ksi = 0.1;
X = 2*pi*frequency*L;
r = [];
y = [];
for R=0:0.1:3
r=[r,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=[y, output];
end
plot (r, y)
legend('Output')
xlabel('R'), ylabel('output')
title('gragh R_output')
but results is not same as i calculate on mathcad im confused here value alfa , fi and teta , it should be in radian or angle

2 commentaires

i learn how to right R with difrent variation but there is other value X with 3 difrent value X = 2.2 mh to x2=2.9 and x3=3.8 . for R i used loop but for x im not sure what to do
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.

Connectez-vous pour commenter.

moji abb
moji abb le 10 Oct 2019
just great !! im so happy to learn something that seems so hard for me thank you ;)
moji abb
moji abb le 10 Oct 2019
the only thing i would love to know is a 3D model of same equation with " output" R" X" AND FI"

7 commentaires

That would be more difficult, because that would be a volume. It would be easy enough to calculate using a vector of values for ‘fi’, since you would just need to add another loop (and another index, probably ‘k3’). See the isosurface function if you want to experiment with that idea.
GOT IT SO USEFULL TUTORIAL I APPRACIAT ALL
Again, my pleasure!
hi again last days im working on code and had some practice but i can not find a solution could you please help me with this. i want to change the position of resistance and inductance i mean x-axis is inductance and those 3 colors output is resistance i tried to change all but I cant not figure out
I do not completely understand what you want to do. I also do not udnerstand what your code is doing.
If you want the functions of inductance to be on the x-axis, just reverse the order of the plot arguments:
plot (y(k1,:), r(k1,:))
and change the axis labels.
sorry for my bad explanation . I try again with attached file in this comment please take a look, in previous code that you help me with we have an eq with 2 variation R & L what I need now is the same cood same number and same out put but x axis I want change from R to L . IT MEAN X AXIS SHOULD BE different variation 2.2 mh . 2.9mh . 3.8 and 3 colorful plot comes with different R VALUE . I hope I could transfer my thought
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.

Connectez-vous pour commenter.

moji abb
moji abb le 11 Oct 2019
could you check where im doing mistake as u said i coe new value k3 but
%%% ====== 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.
F = pi/3;
Fv = 0:0.1:0.3;
Er = 8;
ksi = 0.1;
Xv = 2*pi*frequency*L; % ‘X’ is now vector ‘Xv’
r = [];
y = [];
z = [];
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 = l:numel(Rv)
R = Rv(k2);
for k3 = 1:numel(Fv)
F = fV(k3);
r(k1,k2,k3) = 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,k3) = output;
end
plot (r(k1,:), y(k1,:), z(k3,:))
OutpLeg{k1} = sprintf('Output L = %.1f mH', L(k1)*1000);
end
hold off
legend(OutpLeg)
xlabel('R'), ylabel('output')
title('gragh R\_output')

Catégories

En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by