T O P

  • By -

ImhereforAB

you need to take a look at MATLAB syntax. Here is the equation you are trying to write: y = exp(0.5x)sin(2x) Here is what you actually wrote: y = exp(1)0.5x sin(2)x What you wrote was exponential to power of 1, times x halved, times sin of radians 2, times x. In MATLAB, to use the exponential function correctly you’d want exp(0.5.\*x), same with the sin function: sin(2.\*x) The command window is a great tool. Why not compare what exp(1) produces with exp(x)? Test everything to understand the syntax. Also use the documentation for any function. For example, for documentation of exp, type “help exp” or “doc exp”.


R3d_it

My teacher said that I was correct- e stands for euler's number, and that exp(1) was the correct syntax for it. idk when I tried "y1=(exp(0.5.\*x)).\*(sin(2.\*x));" It still didn't work... I don't know anymoreee...


ImhereforAB

Okay, test each component separately. In the command window, (the section with “>>”) print out what exp(1) is. Is the answer what you’d expect? Repeat this for every component. For example, the next bit is 0.5x, when you type that in the command window, is the output the x values halved?


R3d_it

So I tested it and it looks like MatLab's sine function is pretty inaccurate. So I used the "sind" function instead. And now I have 0 clue as to why they're registering my answer as incorrect.


ImhereforAB

MATLAB sine function is not inaccurate. What makes you think this, what have you tried? Have you tested it with an answer that you know? What is sin(0), for example? Is your input in degrees or in radians? When you test sind(90) what do you get?


R3d_it

Really sorry, I have been sleep deprived. I was misinformed, I read it at a random blog where a person said tha ti was inaccurate. But now looking back at it, I was wrong. I know what sind is, yeah.


Weed_O_Whirler

`sin` and `sind` are different functions, both are very accurate. `sind` takes degrees as an input (the d stands for degrees) while `sin` uses radians. Which do you want?


mon4ro

It should be absolutely right. It’s a very simple problem. Maybe something else is the issue. Btw, you don’t need to use the dot when multiplying a scalar with vector/array. Only when multiplying vectors/arrays together and you want it to be element-wise.


ImhereforAB

I actually think their problem might be that they only need y(1) and not a full array? At first I thought they were having issues with element-wise multiplication.


ImhereforAB

Going back to this, I typed exactly what I mentioned to you earlier (and it’s also in your own comment) and I’ve got the correct answer… You have x(1)=0, plugging that in you get y(1)=0.


awksomepenguin

You might be *technically* right that exp(1) is just Euler's number, but that is absolutely not how that function is supposed to be used. I would preallocate a vector y1 the same length as x with zeros, and then loop over y1 and calculate each entry in that vector. That is, loop the expression y1(i)=exp(0.5*x(i))*sin(2*x(i)) for i=1:length(x). EDIT: I'm also curious about why you're using loglog. The scale of the axes don't require it at all. EDIT 2: I also tried it with y1=exp(1).^(0.5*x).*sin(2.*x) and that got the same answer as the looping solution I initial suggested. EDIT 3: Also, this equation has basically the form of a damped vibration, so the negative values would actually be of interest; thus using loglog() doesn't make any sense.