MATLAB Answers


how can I pass an equation as input parameter to function

Asked by Eman Ahmed Elsayed on 31 May 2011

I write s function which take two parameter the first is an equation and the second is an integer number and I want to substitute with this number in the equation and return the result.

function result=sub(a,c)
%UNTITLED3 Summary of this function goes here
%   Detailed explanation goes here

when I test it on command window I write

     >> result=sub(2*x,1)

I get an error

??? Undefined function or variable 'x'.



No products are associated with this question.

1 Answer

Answer by Eman Ahmed Elsayed on 31 May 2011

I solved my problem

I wrote the function like the following

>> f=@(x) 2*x + 1

and then passed it to the function


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!