The Student Room Group
Reply 1
Get yourself an m file, and put in something like this:
x=input (‘Enter a value for x - ’)
while x>=-6 && x<=-2
f(x)= 2x^2
if x>=-2 && x<=2.5
f(x)=e^3*x
elseif x>=2.5 && x<=6
f(x)=ln(2*x)

Possibly? I'm a matlab noob and don't have it on this computer...haha.
Reply 2
Kittyyyyyyy
Get yourself an m file, and put in something like this:
x=input (‘Enter a value for x - ’)
if x>=-6 && x<=-2
f= 2*x^2
elseif x>=-2 && x<=2.5
f=e^3*x
elseif x>=2.5 && x<=6
f=ln(2*x)
else
f=0
end

Possibly? I'm a matlab noob and don't have it on this computer...haha.


Just fixed the parts in bold for you. The WHILE loop isn't necessary, and you were missing the 'end' from the IF loop. I also added the additional statement at the end that will make f=0 if x is outside the values defined and made the variable f where you put f(x). Putting f(x) willl tell matlab to put the value into index x in array f, which isn't what you want to do.
Reply 3
lol i've no idea who to give the rep to at mid night :tongue:

Latest