Asked by Gabriel Boiling
on 15 Mar 2018

I wrote a non-polynomial function as y and made a plot graph from it but when I try to find a value of x from the function (simply using y(x)) it never seems to match what the value would be from the graph? For instance I can see that when x = 10 then y=-100 from the graph, but using y(10) I get the value x = -188.9. Relevant graph:

and y(10):

relevant code:

a5 = -2 * 10 ^ -5; %assign values of the equation variables

a4 = 3 * 10^ -5;

a3 = 2 * 10^ -2;

a0 = -50;

b1 = -10^ 2;

b2 = 10;

c1 = 2 * 10^ -1;

c2 = 10^ -1;

x= -37:37; %define the range of x for the graph

y = (a5.*x.^5 + a4.*x.^4 + a3.*x.^3 + a0 + b1.*(sin(c1.*x)) + b2.*exp(c2.*x)); %assign the y function

plot(x,y); %plot the graph

xlabel ('X axis'); %add the title, axis and grid to the graph

ylabel ('Y axis');

title ('Figure 1 - Function y as a function of x');

grid on;

end

Answer by Michelangelo Ricciulli
on 15 Mar 2018

Accepted Answer

Steven Lord
on 15 Mar 2018

Easier would be to define an anonymous function and call it to evaluate your mathematical function.

f = @(x) (a5.*x.^5 + a4.*x.^4 + a3.*x.^3 + a0 + b1.*(sin(c1.*x)) + b2.*exp(c2.*x));

y = f(x);

The variable f is an anonymous function and y is the result of evaluating the anonymous function with the data stored in the variable x as input.

Michelangelo Ricciulli
on 15 Mar 2018

Gabriel Boiling
on 15 Mar 2018

Ok then, thank you for all the help

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.