1 Replies - 230 Views - Last Post: 04 June 2013 - 08:58 PM Rate Topic: -----

#1 TurboST2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1