MathLab QUADRATIC equation and VECTORS help!

5 views (last 30 days)
Amed
Amed on 6 Jun 2013
Hi,
I just needed quick help on my MatLab homework.
I'm pretty close I believe, but i'm getting strange errors in which i'm hoping somebody on here can help me out
y(x,a)= xsin(ax−2) 1+(ax)2
−π ≤ x ≤ π
a = {0.5 1.0 1.5 2.0}
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.
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).
Add another cell to create a plot of the solutions with an appropriate legend, x and y-axis labels, and figure title.
So far this is what I have.
%%Quadratic eq function
function [ part1 ] = first(x,a)
mat = x';
scal = a;
quad = (((mat)'*((sin((mat*scal))'-2)')))/(sqrt(1+(mat*scal).^2))
end
----------------------------
%%Main script
range = -pi:0.1:pi;
b = .5:.5:2;
for ind = b;
first(range,b)
end
I'm getting 4 matrices that are 63 columns in length (same size as x), but i'm only getting values in columns 32, 27, 21, and 1..
I'm not sure how to plot.. when I set first(range,b) to a variable I get an error Error in first (line 3) mat = x';
Output argument "part1" (and maybe others) not
assigned during call to
"*location of file*".
Error in cellscript (line 8)
equ = first(range,b)
  4 Comments
Matt Kindig
Matt Kindig on 6 Jun 2013
The first error is because you never actually define a 'part1' variable in your first() function. You need to define this variable (as the output of your equation, i.e., 'quad') for your function to work.
By the way, by my reading of the assignment, your function should be called part1, not your output variable. You are currently calling your function 'first'. So your first line should be:
function [quad]= part1(x,a)

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!