简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM