Where am I going wrong?

Here is my script so far:
% PROGRAM WaterEntry.m
%
% Solving the two-dimensional water entry problem for a given solid
% object falling into a fluid at normal incidence
%
%
%
% PRESCRIBE VARIABLES OF LENGTH
%
%
x=0:0.01:1;
z=0:0.1:10;
t=0:0.1:1;
%
%
%
% CALCULATE SURFACE ELEVATION GRAPH BY INPUTTING SHAPE
%
%
%
prompt = 'What is the shape of the object?';
reply = input(prompt,'s');
%
%
if strcmp(reply,'wedge')
twed = 0:(2*t)/pi:1/pi;
hwed = -twed+(2*x./pi)*asin((pi*twed)./(2*x));
plot (z,hwed)
elseif strcmp(reply,'parabola')
tpara = 0:(x.^2)/2:0.36/2;
hpara = -tpara-(mod(x,0))*(sqrt((x.^2)-(2*tpara)))+(x.^2);
plot (z,hpara)
end
%
%
% END PROGRAM
but when i run the program i get:
>> WaterEntry
What is the shape of the object?wedge
Error using ./
Matrix dimensions must agree.
Error in WaterEntry (line 27)
hwed = -twed+(2*x./pi)*asin((pi*twed)./(2*x));
>> WaterEntry
What is the shape of the object?parabola
Error using -
Matrix dimensions must agree.
Error in WaterEntry (line 31)
hpara = -tpara-(mod(x,0))*(sqrt((x.^2)-(2*tpara)))+(x.^2);
I can not get Matlab to work out the specific equation for a given inputted shape. What do I have to do to solve the problem? Thanks :)

Risposte (1)

Geoff Hayes
Geoff Hayes il 25 Apr 2014
Hi Chris,
You should add some breakpoints to your program and step through the code to see what is happening at line 27. When I run the above with a breakpoint, the twed vector is initialized (at line 26) to a 1x0 empty vector and the error makes sense. (Same thing happens for the parabola choice at line 30 - tpara is a 1x0 empty matrix.)
What are you expecting the twed and tpara to be? In the wedge case, the code is:
twed = 0:(2*t)/pi:1/pi;
So the above is creating a vector from 0 to 1/pi with step size of (2*t)/pi. But t is a vector of 11 elements. What should this be?
Geoff

Categorie

Scopri di più su Graphics Performance in Centro assistenza e File Exchange

Tag

Richiesto:

il 25 Apr 2014

Risposto:

il 25 Apr 2014

Community Treasure Hunt

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

Start Hunting!

Translated by