David
David

Reputation: 62

matlab function files with two variables

i'm having some issues starting off with matlab and the articultion with function files. i have been asked the following. "write a user defined MATLAB function file for the following function z = (x^2 + 1)(y^2 - x) The inputs of the function are x and y and the output is z. Name the function as q2_func. write the function so that x and y can be vectors.

A) use the function q2_func to calculate and display the value of z for x=-3 and y = 3. B) use the function q2_func to calculate and display the value of z for x=[1 2] amd y = 3.

So far for my function file I have the following

function [ z ] = q2_func(x, y) x = (x.^2 + 1)*(y.^2 - x); end

and for the actual matlab programming x1 = q2_func(-3, 3)

when I hit run I get the error undefined function 'q2_func' for input arguments type double

What am I doing wrong so far? any help appreciated, thanks

Upvotes: 0

Views: 195

Answers (1)

am304
am304

Reputation: 13876

First, there is a mistake in your function, it should be z = (x.^2 + 1).*(y.^2 - x);.

Second, have you saved your function as q2_func.m in your current directory or somewhere on the MATLAB path? The error message indicates that MATLAB cannot find the file.

Upvotes: 2

Related Questions