mardi 26 avril 2016

If statements in ode45 function

i am using the following signal as an input in a matlab code that i have made.I have put it inside the ode45 function file but the results that i am getting don't make sense. I have tried using the fixed step ode4 solver and the results are what i expect to be, but i don't want to use a fixed step solver as i don't trust them to produce accurate results.

t = linspace(0,100,10000);
Fmax = 10000;`
ts1 = 1;
ts2 = 2;
ts3= 0;
ts4=2;
tt = ts1+ts2+ts3+ts4;
n = max(size(t));
Fn = zeros(1,n);
for i = 1:n
    B = floor(t(i)/(tt));
    if t(i) <= (B)*tt+ts1
        Fn(i) =Fmax.*((t(i)-B*tt)/ts1); 
    elseif t(i) > (B)*tt+ts1 && t(i) <= (B)*tt+ts1+ts2
        Fn(i) = Fmax;
    elseif t(i) > (B)*tt+ts1+ts2 && t(i) <= (B)*tt+ts1+ts2+ts3
        Fn(i) = -Fmax.*(t(i)-(ts2+ts1)-B*tt)/abs(ts3-ts2)+Fmax;
    elseif t(i) > (B)*tt+ts1+ts2+ts3 && t(i) < (B)*tt+ts1+ts2+ts3+ts4
        Fn(i) = 0;
    end
end

plot(t,Fn)` Of course inside ode function i have taken out the ''for'' part and the i. Thanks

Excel Programming - If Statement

I have coded on C# before and know all of the basics to do with loops and statements. I have been trying to make a simple IF statement on excel but a very unhelpful error comes up every time I try and run it. I was wondering if anyone would be able to point out what I'm doing wrong here -

I'm just trying to output a "Yes" If cell h14 is greater than 250 OR less than 250 AND cell I14 is greater than 0.15 OR less than -0.15 else output "No"

This is what I came up with but it doesn't seem to work: IF((H14>=250 OR H14<=-250) AND (I14 >= 0.15 OR I14 <= -0.15),"Yes", "No")

Many Thanks

AnuglarJs best practice to check if undefined and null

I would like to know which way to check if a var is null or undefined in angularjs is the best way.

First way :

if(!myVar){...}

Second way :

if(myVar === null || myVar === undefined){...}

Third way :

if(angular.isUndefined(myVar) || myVar === null){...}

I prefere the first one but I want to be sure if it's the best way. The problem with the last one is that I use an angular's function to test if it's undefined and a native JavaScript's way to check if it's null.

Thanks everyone !

Cannot convert call result type "Bool" to expected type int?

I'm trying to change daysMonth[2] to 29 but I get an error in the if statement. Can you resolve the above error?

var rem4 = 0;
var rem100 = 0;
var rem400 = 0;

//error Cannot convert call result type "Bool" to expected type "Int"
if (((rem4 == 0 && rem100 != 0) | rem400 == 0)){
     daysMonth[2] = 29
}

Using Ternary Operator to implement else if in EL - jsf

I have an application being developed in jsf 2.0, primefaces and using Eclipse Kepler IDE. I need to display a string value in dataTable for long value. There could be 6 possible values from 1 to 6. i have followed this question to solve my issue but i cant. my code snipped is

  <p:dataTable var="student" value="#{studentBean.studentList}">
  <p:column headerText="Class">
    <h:outputText value="#{student.studentClass == 1? 'One' :
                           student.studentClass == 2? 'Second' :
                           student.studentClass == 3? 'Third' :
                           student.studentClass == 4? 'Fourth' :
                           student.studentClass == 5? 'Fifth':
                           student.studentClass == 6? 'Sixth':''}" />
  </p:column>
      ....

i also tried:-

   student.studentClass.equals(1l) and  student.studentClass.equals(1L)

but no luck. What am i doing wrong

Multiple ifs in a stream using filters

How can we represent the following using streams and filters. Thanks.

for (UIDisplayItem uiDisplayItem : uiDisplayItems) {
    if ("8929".equals(uiDisplayItem.getProductSpecCharacteristicID())) {
        type1 = uiDisplayItem.getValue();
    }
    if ("5121".equals(uiDisplayItem.getProductSpecCharacteristicID())) {
        type2 = uiDisplayItem.getValue();
    }
    if ("4981".equals(uiDisplayItem.getProductSpecCharacteristicID())) {
        type3 = uiDisplayItem.getValue();
    }
    if ("501".equals(uiDisplayItem.getProductSpecCharacteristicID())) {
        type4 = uiDisplayItem.getValue();
    }
}

AngularJS: if(obj) vs if(obj!==null & angular.isDefined(obj))

Which is better way to compare the definition of an object? if(obj!==null & angular.isDefined(obj) or if(obj)?

Would love to know the use and abuse of both methods.