Solving equations using MATLAB

126 Views Asked by At

I got an online question which I couldn’t understand.

The question is:

Create a script to ask the user to create a random number using the following equation : question

  1. Plot x(t) with customize the figure yellow and red color and dash line.
  2. Solve the equation with symbolic and differentiate it.

I tried to solve it as following:

clc; clear all; 

syms x;
Xt = int(100*rand*sin(x),-100,100); 
plot(Xt);   % The first question 
Y = solve(100*rand*sin(x)); 
Y2 = diff(Xt,x);

The problem I face is that Xt, Y and Y2 are all zeros. Did I understand the question right? How to solve it?

1

There are 1 best solutions below

0
MichaelTr7 On BEST ANSWER

Possibly, could plot the functions with respect to x. Kinda concerned since the function is called X(t) though. Seems like it should be changing with respect to t or some kind of time variable. The colour and line properties can be configured by adding the short-hand for the colour followed by the line type in this case I used a dashed red line denoted as r-- in the fplot() line. In this example, I also used hold on to add a yellow underline. If you need the figure background colour to be yellow add set(gcf,'color','y'); to configure the current figure, gcf. Not quite sure which portions or plots need the yellow colour. To plot symbolic functions using the fplot() function can be a useful method. This function can optionally take a second argument that is an array describing the horizontal/x-axis bounds/range to plot the function for. Also note that rand will only evaluate to doubles in the range from 0 to 1.

Plot of Integrated and Derived Functions

clear;
clc; 
clf;

syms x;

Xt = int(100*rand*sin(x)); 
Lower_Bound = -100;
Upper_Bound = 100;

subplot(2,1,1); fplot(Xt,[Lower_Bound Upper_Bound],'y');  
hold on
subplot(2,1,1); fplot(Xt,[Lower_Bound Upper_Bound],'r--'); 
title("Plot of X(t)");
xlabel("x"); ylabel("Amplitude");
hold off

Solution = int(100*rand*sin(x),Lower_Bound,Upper_Bound); 
Solution

Y2 = diff(Xt,x);

subplot(2,1,2); fplot(Y2,[Lower_Bound Upper_Bound])
title("Differentiation of X(t) -> Y(t)");
xlabel("x"); ylabel("Amplitude");

Ran using MATLAB R2019b