How do I use modulus operator in Reason React? - reason

When using the % operator in reason react I am left with an error "The value % can't be found". Is there another word for % used in Reason react?
Js.log(20 % 2)

Reason syntax for modulus is "mod".
Js.log(20 mod 2)

Related

Evaluating an expression using MATLAB

I am trying to evaluate a parameter using Matlab , here is the code
miu_not=1.257*1e-6; % permeability of free space
efslon_not=8.854*1e-12;% permittivity of free space
efslon_rg=input('Enter the relative permittivity of ground ')
segma_g=input('Enter the ground conductivity') ;
b=input('enter the conductor radius');
f= input('Enter the frequency');
w=2*pi*f;
prop_ground=sqrt(1i*w*miu_not(segma_g+(1i*w*efslon_not*efslon_rg)))
It is giving me an error regarding the indices for the last line that it must be positive or logic , while i don't have any array in the equation ???
The exact error message is:
Array indices must be positive integers or logical values.
Error in Untitled (line 8)
prop_ground=sqrt(1i*w*miu_not(segma_g+(1i*w*efslon_not*efslon_rg)))
In your last statement
prop_ground=sqrt(1i*w*miu_not(segma_g+(1i*w*efslon_not*efslon_rg)))
is there supposed to be an operator between the miu_not and segma_g?
I think it's evaluating to miu_not(%number%) so Matlab thinks you're trying to index miu_not by number.

MATLAB: Using FZERO on a function which has a vector output

I am working on my thesis and running in some programming problems in Matlab. I am trying to implement the ''golden Bisection Method'' to speed up my code. To this end, I've consulted the build in function FZERO.
So I am determining the difference between two vectors which are both (1x20).
Difference = Clmax_dist-cl_vec;
Clmax_dist comes from a semi-empirical method and cl_vec comes from the excecution of an external AVL.exe file.
Essentially, this difference depends only on one single variable AOA because the Clmax_dist vector is a constant. Hence, I am constantly feeding a new AOA value to the AVL.exe to obtain a new cl_vec and compare this again to the constant Clmax_dist.
I am iterating this until one of the element in the vector becomes either zero or negative. My loop stops and reveals the final AOA. This is a time consuming method and I wanted to use FZERO to speed this up.
However, the FZERO documentation reveals that it only works on function which has a scalar as input. Hence, my question is: How can I use FZERO with a function which has a vector as an output. Or do i need to do something totally different?
I've tried the following:
[Difference] = obj.DATCOMSPANLOADING(AOA);
fun=#obj.DATCOMSPANLOADING;
AOA_init = [1 20];
AOA_root = fzero(fun,AOA_init,'iter');
this gave me the following error:
Operands to the || and && operators must be convertible to logical scalar values.
Error in fzero (line 423)
while fb ~= 0 && a ~= b
Error in CleanCLmax/run (line 11)
AOA_root = fzero(fun,AOA_init,'iter');
Error in InitiatorController/moduleRunner (line 11)
ModuleHandle.run;
Error in InitiatorController/runModule (line 95)
obj.moduleRunner(ModuleHandle);
Error in RunSteps (line 7)
C.runModule('CleanCLmax');
The DATCOMSPANDLOADING function contains the following:
function [Difference] = DATCOMSPANLOADING(obj,AOA)
[Input]= obj.CLmaxInput; % Creates Input structure and airfoil list
obj.writeAirfoils(Input); % Creates airfoil coordinate files in AVL directory
[Clmax_dist,YClmax,Cla_mainsections] = obj.Clmax_spanwise(Input); % Creates spanwise section CLmax with ESDU method
[CLa] = obj.WingLiftCurveSlope(Input,Cla_mainsections); % Wing lift curve slope
[Yle_wing,cl_vec] = obj.AVLspanloading(Input,CLa,AOA); % Creates spanloading with AVL
Difference = Clmax_dist-cl_vec;
end
If I need to elaborate further, feel free to ask. And of course, Thank you very much.
fzero indeed only works on scalars. However, you can turn your criterion into a scalar: You are interested in AOA where any of the elements in the vector becomes zero, in which case you rewrite your objective function to return two output arguments: minDifference, which is min(Difference), and Difference. The first output, minDifference is the minimum of the difference, i.e. what fzero should try to optimize (from your question, I'm assuming all values start positive). The second output you'd use to inspect your difference vector in the end.

unexpected matlab expression very simple code.

There seems to be a small problem with my matlabcode.
i'm trying to calculate Qx using this simple formula.
Anybody has an idea what i'm doing wrong?
Error: File: functie5612.m Line: 2 Column: 28
Unexpected MATLAB expression.
Error in oef5612 (line 2)
Qx=functie5612(D)
Define my function
function Qx=functie5612(D)
Qx= D*(11-(0.1*D)/(0.28-D))0.8
end
Initial parameter
D=[0;2;4;6;8;10;12;14;16;18;20;22;23;24;25;26;27;28;30;32;34;36;38]
Using my function
Qx=functie5612(D)
making a graph
clf
figure(1);
plot(D,Qx);
title ('Optimale dilutiesnelheid','FontSize',12);
xlabel('D(1/h)','FontSize',12);
ylabel('Volumetrische biomassaproductiviteit(kg/(m^3*h)','FontSize',12);
legend('Substraat','Product','Biomassa') `
You need the explicit * when doing multiplication. That is, you should have )*0.8 and not just )0.8.
So your function should look like:
function Qx=functie5612(D)
Qx= D*(11-(0.1*D)/(0.28-D))*0.8
end
However, this is still incorrect (dimensions mismatch). If you are looking at elementwise multiplication of D, you will need to use the . operator. The code would look like:
Qx= D.*(11-(0.1*D)./(0.28-D))*0.8
The error you get is due to a matrix dimesion mismatch.
So, you need to use the .* operator instead of *
Qx= D.*(11-(0.1.*D)./(0.28-D)).*0.8;

plotting from a loop

for t=0:0.1:10;
VS=3*exp(-t/3).*sin(t*pi);
if VS>0
VL(t+1)=VS;
else
VL(t+1)=0;
end
end
plot(0:100,VL);
xlabel('Time(s)')
ylabel('Across Voltage(V)')
title('Across Voltage Vs Time')
how to plot this figure based on VL (based on the relationship with VS whose expression shows above) versus t(from 0 to 10, increment 0.01)?
always got the error from matlab "Subscript indices must either be real positive integers or logicals."
Thanks.
There is a problem in your script. Note that t is defined in 0.1 intervals. Therefore, it is a real variable and can't be used as a subscript indice.
One way to solve that is
1) write cont=0; before the loop for.
2) write cont=cont+1 in the beginning of the loop
3) replace VL(t+1) by VL(cont)in both places inside the loop

How can I display an error message in MATLAB?

I was doing a model for a slider-crank mechanism and I wanted to display an error for when the crank's length exceeds that of the slider arm. With the crank's length as r2 and the slider's as r3, my code went like this:
if r3=<r2
error('The crank's length cannot exceed that of the slider')
end
I get the error:
??? error('The crank's length cannot exceed that of the slider')
|
Error: Unexpected MATLAB expression.
can someone tell me what I'm doing wrong and how to fix it please?
When you want to use the ' character in a string, you have to precede it with another ' (note the example in the documentation):
if (r3 <= r2)
error('The crank''s length cannot exceed that of the slider');
end
Also, note the change I made from =< to <=.
You can print to the error handle as well:
fprintf(2,'The crank''s length cannot exceed that of the slider');
I believe the comparison operator should be <= not the other way around, unless that was only a typo in your question
Also you should escape the ' character using ''