Turn on thread page Beta
    • Thread Starter
    Offline

    0
    ReputationRep:
    f(x) = { 2x^2 for -6 ≤ x ≤ -2
    e^3x for -2 ≤ x ≤ 2.5
    ln(2x) for 2.5 ≤ x ≤ 6 }

    (this is just a made up example question, so that you're not helping me directly do my coursework ^^)

    so. I need to use a CONDITIONAL STATEMENT in MATLAB to evaluate these ...

    roughly how do i do it XD

    Thanks!! I will rep the first most helpful anser at 00:00
    Offline

    0
    ReputationRep:
    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.
    Offline

    0
    ReputationRep:
    (Original post by 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.
    • Thread Starter
    Offline

    0
    ReputationRep:
    lol i've no idea who to give the rep to at mid night
 
 
 
Reply
Submit reply
Turn on thread page Beta
Updated: February 14, 2010

University open days

  1. University of Bradford
    University-wide Postgraduate
    Wed, 25 Jul '18
  2. University of Buckingham
    Psychology Taster Tutorial Undergraduate
    Wed, 25 Jul '18
  3. Bournemouth University
    Clearing Campus Visit Undergraduate
    Wed, 1 Aug '18
Poll
How are you feeling in the run-up to Results Day 2018?
Useful resources

Make your revision easier

Maths

Maths Forum posting guidelines

Not sure where to post? Read the updated guidelines here

Equations

How to use LaTex

Writing equations the easy way

Student revising

Study habits of A* students

Top tips from students who have already aced their exams

Study Planner

Create your own Study Planner

Never miss a deadline again

Polling station sign

Thinking about a maths degree?

Chat with other maths applicants

Can you help? Study help unanswered threads

Groups associated with this forum:

View associated groups

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.