I need to find values of a piece wise linear function.
I used nested if condition as shown in code.
But for all values of t, it is executing only first "if else" loop, and giving always x1d(t)= 0.5 andx2d(t)= 0.5 as output values.
Am not able to figure out the mistake. help me.

Products

2 Answers

This if 0<t<=4 doesn't work properly in MATLAB, but this does if 0<t && t<=4 , you have to separate the conditions because MATLAB doesn't evaluate two conditions at the same time unless you use & or | operators.

This logical expression would take an eagle-eyed programmer
anywhere from 10 mins to a day to check for errors (precedence
rules for && versus ||, etc.).

This is crazy. Any compiler-interpreter that rejects 4 < t <= 7 is
doing so for purely lexical-syntactical convenience. This is not a
code generation problem. Most 1st or 2nd-year computer science
students could write a (character-by-character) program that would
translate

4 < t <= 7 into 4 < t && t <= 7.

For me, the key to Matlab's success, and what attracted me, was the
important syntactical innovation by Cleve Moler: a notation that
made it easy to translate statements in Linear Algebra into a
programming language. This is what IBM's Jim Backus tried to do with
the FORTRAN (FORmula TRANslation) (56?) compiler. He succeeded,
despite the sceptics, and Cleve Moler succeeded, despite the
sceptics, to produce programming languages that are widely used in
scientific computing.

So, in typical Irish fashion, I will answer your question with a
question:

Why can't Matlab, etc., recognize the simple statement

if 4 < t <= 7

Derek O'Connor.

PS: Another question: why is it so difficult to write anything but
plain text on this site?