Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Simple Matlab

  1. Apr 7, 2009 #1
    Im a begginer at Matlab and have a simple question.

    I have a equation with lots of variables that can be easily entered incorrectly.

    Therfore i was going to split up the term.

    For example if i have y = x^(6Z+2) i was going to put the m file as


    u = 6Z + 2

    then z = 3 for example.

    but i tried something like this and it didnt work, could anyone help me.

    function z = f(c)
    z = c^h
    this is what i tried
  2. jcsd
  3. Apr 7, 2009 #2


    User Avatar
    Science Advisor

    You can't do things symbolically like that with plain-jane MATLAB; if you reverse the order of the operations, MATLAB will be happy.

    Code (Text):
    function z = f(c)
  4. Apr 13, 2009 #3
    y = x^(6Z+2)

    Code (Text):
    y = @(x,z)(x^(6Z+2))
    then to evaluate y at x=3 and z=4, run:

    Code (Text):
    or if you want to put it in a m file:
    Code (Text):
    function y = functionName(x,z)
    y = x^(6Z+2);
    and save it as functionName in your MATLAB directory.

    then you would run functionName(3,4) to evaluate y(3,4)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook