This is my first Matlab and I am stuck on this problem: The general solution to
ID: 1942850 • Letter: T
Question
This is my first Matlab and I am stuck on this problem:
The general solution to the differential equation
dy/dx = x + 2 is
y(x) =x2/2+ 2x + C with y(0) = C:
The goal of this exercise is to write a function file to plot the solutions to the differential equation
in the interval 0 x 4, with initial conditions y(0) = 1; 0; 1.
Similarly to the M-file myplot1.m , write a function file to plot the three solutions. The function that defines y(x) must be included in the same file (note that the function
defining y(x) will have two input arguments: x and C). Use the command hold on to plot the graphs on the same window and use different line-styles for each graph.
I know that the format for this function file will be:
function [ output_args ] = Untitled6( input_args )
%UNTITLED6 Summary of this function goes here
% Detailed explanation goes here
But I have no idea what I should be typing into output args and input args. I tried to put in the numbers but I keep getting an error..
Explanation / Answer
clc; clear all; C = [0 1 2]; x= 0:0.1:4 hold on; for i=1:1:3 for j=1:1:41 y(1,j) = x(1,j)*x(1,j)/2 + 2*x(1,j)+ C(1,i) ; end plot(x,y); end hold off;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.