0
votes

I'm working on numerical computation methods. I'm new to octave. I download two m files from the internet. Here I just gonna show you the problem-related code, not the whole code.

From funct.m file:

function [ y ] = funct (x)
y=(x*(exp((-x)+3)))-sin((7*x)-4)+(8*x)-20
endfunction

I Think there is no problem there. The error occurred when I tried to plot the function in secant.m file. I've tried two kind of plotting functions. plot() and fplot()

secant.m file:

1.plot():

x=linspace(0,10,20); 
plot(x, funct(x));

The error message is nonconformant arguments (op1 is 1x20, op2 is 1x20)

2.fplot():

fplot(funct(x),[0,10],10)

The error message is nonconformant arguments (op1 is 5x1, op2 is 5x1)

How can I fix this error? I'm familiar with other programming language, especially C-like syntax, so feel free to answer it in technical way.

1
try to change * with .* in declaration of funct or y=zeros(size(x)) and define each y(ii) value in for loop. - Crowley

1 Answers

0
votes

You will need to use the element-wise multiplication operator (.*) in your funct equation.

y = x .* exp(-x + 3) - sin(7*x - 4) + 8*x - 20

This is because you want each element of x to be multiplied by each element of exp(-x + 3)