# Matlab Functions

Page 1 of 1

## 1 Replies - 431 Views - Last Post: 04 June 2013 - 08:58 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=322420&amp;s=d9e02375f6602e7c93c2cacce36c6df6&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 TurboST2

Reputation: 0
• Posts: 36
• Joined: 11-November 11

# Matlab Functions

Posted 04 June 2013 - 04:32 PM

Here is my problem:

Part 1 – Plotting and Varying Parameters

y(x,a) = (xsin(ax −2))/(sqrt(1+(ax)^2))
−π ≤ x ≤π
a = {0.5 1.0 1.5 2.0}

A. Create a function called part1 in a separate m-file that will take a
vector/array input for x (1 by n) and a scalar input for a, and produce the
corresponding output defined by the equation above. The equation must be
vectorized in terms of x. The output from your function is the array y
which should be the same dimensions as the array x.

B. Write a cell mode script that calls the function you created in part 1A, to
compute y(x,a) for the range of x defined above and each value of the
parameter a. You must STORE YOUR RESULTS in some sort of solution
matrix (i.e. set the values of y(x,a), using a different row of the solution
matrix for each value of a).

C. Add another cell to create a plot of the solutions with an appropriate
legend, x and y-axis labels, and figure title.

For part A here is my function:

```function [y] = part1(x,a)

y=((x*sin(a*x-2))/(sqrt(1+(a*x).^2)));

end
```

For part B this is what I've got so far:

```%%
clear,clc

for x=-pi:pi
a=.5:.5:2;
part1(x,a)
end

```

I'm stuck here and really don't know how to even begin to progress any further with it. I do know how to do part © with no issues I don't need any help in that area. Any help for part A and B would be greatly appreciated.

Thank you

This post has been edited by TurboST2: 04 June 2013 - 04:35 PM

Is This A Good Question/Topic? 0

## Replies To: Matlab Functions

### #2 TurboST2

Reputation: 0
• Posts: 36
• Joined: 11-November 11

## Re: Matlab Functions

Posted 04 June 2013 - 08:58 PM

Still working on this. I've made some progress but am still in need of some help. here is an update on where I stand:

Function

```function [y] = part1(x,a)

nx=numel(x);
na=numel(a);

y=((x.*sin(a.*x-2))./(sqrt(1+(a.*x).^2)));
size(y)=[nx na]
end
```

Script

```%%
clear,clc

a={0.5 1 1.5 2};
x=-pi:0.1:pi;

for i = 1:length(a)
y(i,:)/>/>=part1(x,a(i));
end
```

Errors

```Undefined function 'times' for input arguments of type 'cell'.

Error in part1 (line 6) y=((x.*sin(a.*x-2))./(sqrt(1+(a.*x).^2)));

Error in labtest2 (line 8) y(i,:)/>/>=part1(x,a(i));
```

This post has been edited by TurboST2: 04 June 2013 - 08:59 PM